2021-06-10 1 分钟 0.2 k0次访问
docker安装mysql
1.拉取镜像
docker pull mysql:8.0
2.创建数据目录和配置文件
本地1 2 3
| mkdir /home/jmlib/docker-v/mysql8/data
mkdir /home/jmlib/docker-v/mysql8/cnf
|
3.创建配置文件
本地1
| vim /home/jmlib/docker-v/mysql8/data/my.cnf
|
服务1
| vim /home/jmlib/docker-v/mysql8/data/my.cnf
|
配置详情1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| [client]
default-character-set = utf8mb4
[mysqld]
datadir = /usr/mysql/data
character_set_server = utf8mb4
collation_server = utf8mb4_bin
secure-file-priv= NULL
symbolic-links=0
!includedir /etc/mysql/conf.d/
|
4.启动容器
本地1 2 3 4 5
| docker run -d -p 3306:3306 \ -v /home/jmlib/docker-v/mysql8/data/my.cnf:/etc/mysql/my.cnf \ --restart=unless-stopped \ -e MYSQL_ROOT_PASSWORD=123456 \ --name mysql mysql:8.0
|
服务1 2 3 4 5 6 7
| docker run -d -p 3306:3306 \ -v /home/jmlib/docker-v/mysql8/cnf/my.cnf:/etc/mysql/conf.d/my.cnf \ -v /home/jmlib/docker-v/mysql8/data:/var/lib/mysql \ -v /home/jmlib/docker-v/mysql8/home:/home \ --restart=always \ -e MYSQL_ROOT_PASSWORD=123456 \ --name mysql mysql:8.0
|
5.mysql初始化
初始化详情1 2 3 4 5
| docker exec -it mysql bash mysql -uroot -p use mysql ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yiluxiangbei'; flush privileges;
|