拉取mysql 5.7
docker pull mysql:5.7
启动服务
docker run -d -p 3306:3306 --privileged=true -v /Docker_mysql/mysql/log:/var/log/mysql -v /Docker_mysql/mysql/data:/var/lib/mysql -v /Docker_mysql/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -e LANG="C.UTF-8" --name mysql mysql:5.7
参数说明
-p 3306:3306: 将容器的3306端口映射到主机的3306端口
-v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
-v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=root:初始化root的密码
[root@192 mysql]# pwd /Docker_mysql/mysql
[root@192 conf]# pwd /Docker_mysql/mysql/conf [root@192 conf]# vim my.cnf //配置内容 [client] default_character_set=utf8 [mysqld] collation_server = utf8_general_ci character_set_server = utf8
[root@192 conf]# docker ps [root@192 conf]# docker restart mysql
连接宿主机ip及对应端口操作数据库即可