一、下载mysql
docker pull mysql:5.7二、启动mysql, -v为挂载linux外部目录和docker内部mysql目录,一 一对应 -p 为端口映射 -d 后台运行容器,并返回容器ID; -e 设置环境变量
sudo 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三、配置mysql,在linux下
vim /mydata/mysql/conf/my.cnf [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
docker restart mysql五、设置启动docker时,即运行mysql
docker update mysql --restart=always