1,查询 docker search mysql
image.png
2, docker pull mysql
3, mkdir -p /usr/mysql/conf /usr/mysql/data
4, chmod -R 755 /usr/mysql/
5, vim /usr/mysql/conf/my.cnf
内容如下:
[client]
#socket = /usr/mysql/mysqld.sock
default-character-set = utf8mb4
[mysqld]
#pid-file = /var/run/mysqld/mysqld.pid
#socket = /var/run/mysqld/mysqld.sock
#datadir = /var/lib/mysql
#socket = /usr/mysql/mysqld.sock
#pid-file = /usr/mysql/mysqld.pid
datadir = /usr/mysql/data
character_set_server = utf8mb4
collation_server = utf8mb4_bin
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Custom config should go here
!includedir /etc/mysql/conf.d/
6,假设密码设为123456,运行以下指令:
docker run --restart=unless-stopped -d --name mysql -v /usr/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /usr/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
image.png
8,登录容器中的mysql
docker exec -it mysql ./bin/bash
7,授权
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
8,用客户端HeidiSQL连接mysql,成功连接
9,确认在阿里云的安全组中配置规则,开放3306端口
网友评论