目录
- mac通过docker一键部署MySQL8
- 一、前言
- 二、系统配置
- 三、安装步骤
- Dockerhub查看镜像地址
- 1、一键安装
- 1.1、克隆脚本
- 1.2、安装程序
- 1.2.1、安装程序详情
- 1.3、初始化用户
- 1.3.1、安装程序详情
- 1.4、测试数据库是否连接成功
- 四、总结
- 五、后记
二、系统配置
mac os:Montereymac version:12.4 (21F79)mac type: MacBook Air (M1, 2020), Apple M1docker desktop version:v4.10.0docker version:v20.10.17docker-compose version: v1.29.2
三、安装步骤Dockerhub查看镜像地址# 如果你比较懒可以使用最后的“MySQL8自动安装脚本”,mac电脑通用https://hub.docker.com/_/mysql/tags
1、一键安装1.1、克隆脚本git clone git@gitee.com:xiaoyaojiugui/technical.git
1.2、安装程序# 1.跳转到下载脚本的根目录,执行命令:cd /technical/docker/foundations/database/mysql# 2.执行安装脚本,执行命令:sh ./mysql.sh# 3.选择待安装的 MySQL 序号
1.2.1、安装程序详情---------------函数开始执行------------------------------环境变量初始化开始---------------1.1、请选择要安装的 MySQL 版本,例如:MySQL8,输入“1”回车 。1、MySQL8 (Mac with Apple chip or Intel chip)2、MySQL8 (Linux)3、MySQL5请输入序号:11.2、你选择了安装:MySQL8 (Mac with Apple chip or Intel chip)1.3、初始化 MySQL 环境变量image_alias=mysql8image_name=mysql/mysql-server:latestmysql_port=33306os_path=/Users/jason.zhuo/data/docker/volumes/mysql8---------------环境变量初始化完毕---------------1.1、执行创建容器操作,跳过此步骤,镜像已存在[mysql/mysql-server:latest]1.2、执行创建容器操作,创建目录并授权,执行命令:sudo mkdir -p -v /Users/jason.zhuo/data/docker/volumes/mysql8/{data,logs,conf} && sudo chown -R jason.zhuo /Users/jason.zhuo/data/docker/volumes/mysql81.3、执行创建容器操作,创建文件my.cnf并将配置写到文件中[/Users/jason.zhuo/data/docker/volumes/mysql8/conf/my.cnf]1.4、执行创建容器操作,执行命令:docker run -d -p 33306:3306 -d --restart=always --privileged=true -e MYSQL_ROOT_PASSWORD=root123456 -v /Users/jason.zhuo/data/docker/volumes/mysql8/conf/:/etc/mysql/conf.d/ -v /Users/jason.zhuo/data/docker/volumes/mysql8/data:/var/lib/mysql -v /Users/jason.zhuo/data/docker/volumes/mysql8/logs:/var/log/mysql --name mysql8 mysql/mysql-server:latest1.5.1、查看容器状态,执行命令:docker inspect --format='{{.State.Status}}' mysql81.5.2、查看容器状态,[running]1.5.3、查看容器详情,执行命令:docker ps | grep mysql/mysql-server:latest2.1、其他待执行命令,登录容器其命令为:docker exec -it mysql8 mysql -uroot -proot---------------函数执行完毕---------------
1.3、初始化用户- 初始化用户(admin)默认密码(admin123456);
- 请在脚本中(create-user.sh),自行更改密码;
# 1.跳转到下载脚本的根目录,执行命令:cd /technical/docker/foundations/database/mysql# 2.执行安装脚本,执行命令:sh ./create-user.sh# 3.选择待安装的 MySQL 序号
1.3.1、安装程序详情---------------函数开始执行------------------------------环境变量初始化开始---------------1.1、请选择要安装的 MySQL 版本,例如:MySQL8,输入“1” 回车 。1、MySQL8 (Mac with Apple chip or Intel chip)2、MySQL8 (Linux)3、MySQL5 (通用)请输入序号:11.2、你选择了安装:MySQL8 (Mac with Apple chip or Intel chip)1.3、初始化 MySQL 环境变量image_alias=mysql8image_name=mysql/mysql-server:latestmysql_port=33306os_path=/Users/jason.zhuo/data/docker/volumes/mysql8---------------环境变量初始化完毕---------------1、创建数据库用户(admin)并授权,执行命令:docker exec -it mysql8 mysql -uroot -proot123456spawn docker exec -it mysql8 mysql -uroot -proot123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.Commands end with ; or \g.Your MySQL connection id is 10Server version: 8.0.27 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database|+--------------------+| information_schema || mysql|| performance_schema || sys|+--------------------+4 rows in set (0.01 sec)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> create user 'admin'@'localhost' identified by 'admin123456';Query OK, 0 rows affected (0.02 sec)mysql> grant all privileges on *.* to 'admin'@'localhost';Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> create user 'admin'@'%' identified by 'admin123456';Query OK, 0 rows affected (0.00 sec)mysql> grant all privileges on *.* to 'admin'@'%';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> select host, user, plugin from user;+-----------+------------------+-----------------------+| host| user| plugin|+-----------+------------------+-----------------------+| %| admin| caching_sha2_password || localhost | admin| caching_sha2_password || localhost | healthchecker| caching_sha2_password || localhost | mysql.infoschema | caching_sha2_password || localhost | mysql.session| caching_sha2_password || localhost | mysql.sys| caching_sha2_password || localhost | root| caching_sha2_password |+-----------+------------------+-----------------------+7 rows in set (0.00 sec)mysql> exitBye2、成功创建数据库用户:admin---------------函数执行完毕---------------
经验总结扩展阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 松江有轨电车怎么买票
- docker搭建yapi接口文档系统、Idea中上传接口、在线调用
- Docker | 镜像浅析,以及制作自己的镜像
- 钢厂用石墨电极干嘛
- 天空为什么是蓝的
- .NET 开源项目推荐之 直播控制台解决方案 Macro Deck
- docker搭建个人云盘可道云kodbox
- 肺癌的治疗方法有哪些
- 盆腔炎通过什么检查出来
- 贫血多吃什么水果好