1、拉取mysql:8.0镜像

docker pull mysql:8.0

2、启动容器

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

3、进入容器

docker exec -it <数据库容器Id> /bin/bash

4、登录

mysql -u root -p123456 -h localhost

5、切换数据库

use mysql

6、设置远程访问

查看:select host,user,plugin from user;
删除多余的行:delete from user where user ='root' and host='%';
设置所有host可以访问:update user set host='%' where user ='root';
修改密码:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
刷一下,使之生效:FLUSH PRIVILEGES;
退出:exit

原文链接:https://blog.csdn.net/qq_42077539/article/details/127007906