docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /var/mysql/lib:/var/lib/mysql:rw -v /var/mysql/mysql-files:/var/lib/mysql-files:rw -v /var/mysql/log:/var/log/mysql:rw -v /var/mysql/etc:/etc/mysql:rw -v /etc/localtime:/etc/localtime:ro --name mysql --restart=always -d mysql:8.0.16
查看docker:
docker ps
![](https://gitee.com/g403020919/pic/raw/master/20210301202937.png)
docker exec -it 28bc5ff6de08 /bin/bash
//进入了docker镜像内部
mysql -uroot -p
//输入初始密码:123456
![](https://gitee.com/g403020919/pic/raw/master/20210301203213.png)
use mysql; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; FLUSH PRIVILEGES;
![](https://gitee.com/g403020919/pic/raw/master/20210301203532.png)
navicat链接测试:
![](https://gitee.com/g403020919/pic/raw/master/20210301203746.png)