拉取 mysql 镜像

docker pull mysql:latest

启动 mysql

docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

进入 mysql

docker exec -it mysql bash

连接mysql

mysql -h localhost -u root -p

设置mysql的远程连接

1 use mysql;
2 ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
3 FLUSH PRIVILEGES;

如果远程连接不上,建议重启一下容器再试

docker restart CONTAINER ID

----------------------------- 备忘记录,快速上手操作