1.拉镜像
docker pull mysql:5.7
2.运行容器
docker run --name mysql --restart always --privileged=true -p 3306:3306 -v /usr/local/mysql/conf/:/etc/mysql/mysql.conf.d/ -v /usr/local/mysql/data/:/var/lib/mysql/ -e MYSQL_USER="alan6" -e MYSQL_PASSWORD="alan6" -e MYSQL_ROOT_PASSWORD="alan6" -d mysql:5.7
3.在/usr/local/mysql/conf/下添加配置文件my.cnf,内容如下,然后重启mysql
[client] # 对本地的mysql客户端的配置 default-character-set = utf8 # 对其他远程连接的mysql客户端的配置 [mysql] default-character-set = utf8 # 本地mysql服务的配置 [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 #5.7高版本没有修改sql_mode会报ONLY_FULL_GROUP_BY错误 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION