1、拉取镜像
docker pull mysql:5.7
2、启动mysql5.7镜像
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
参数说明
-p
3306:3306:将容器的 3306 端口映射到主机的 3306 端口
-v
/mydata/mysql/conf:/etc/mysql 将配置文件夹挂载到主机
-v
/mydata/mysql/log:/var/log/mysql 将日志文件夹挂载到主机
-v
/mydata/mysql/data:/var/lib/mysql/ 将配置文件夹挂载到主机
-e
MYSQL_ROOT_PASSWORD=root 初始化 root 用户的密码
3、mysql配置文件
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
注意:解决 MySQL 连接慢的问题
在配置文件中加入如下,并重启 mysql
[mysqld]
skip-name-resolve
解释:
skip-name-resolve:跳过域名解析
4、登录容器内部mysql数据库
docker exec -it mysql mysql -uroot -proot
4、设置mysql远程root访问
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
标签:set,mydata,utf8,mysql5.7,mysql,3306,Docker,root,数据库
From: https://www.cnblogs.com/ccblblog/p/17904097.html