1.docker pull mysql:5.7
2.查看镜像-----docker images
3.创建实例并启动mysql
docker run -p 3306:3306 --name mysql \
-v /home/mydata/mysql/log:/var/log/mysql \
-v /home/mydata/mysql/data:/var/lib/mysql \
-v /home/mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
参数说明:
-p 3306:3306 将容器的3306端口映射到主机
-v /home/mydata/mysql/log:/var/log/mysql\ 将日志文件挂载到主机
-v /home/mydata/mysql/data:/var/lib/mysql\ 将数据文件挂载到主机
-v /home/mydata/mysql/conf:/etc/mysql\ 将配置文件挂载到主机
4.查看docker容器
docker ps
5.连接数据库
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;