docker搭建MySQL8.0无法远程连接

docker exec -it mysql bash
mysql -uroot -p123456-abc
select host, user, authentication_string, plugin from user;

docker搭建MySQL8.0无法远程连接_第1张图片
我,竟然有两个root,可能在造成冲突。先删除 host="%'的root账户。毕竟不知道它的密码是什么,因为两个密码不一致。所以保留了localhost的root。

delete from user where host="%" and user="root";

docker搭建MySQL8.0无法远程连接_第2张图片
删除之后,就修改剩余 root 用户 ,把host修改为%

update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
alter user 'root'@'%' identified with mysql_native_password by '123456';

docker搭建MySQL8.0无法远程连接_第3张图片
一般来说,远程访问数据库都是新建一个授权用户的,不直接使用root用户进行远程访问。

你可能感兴趣的:(容器,Linux,mysql)