解决Docker中Mysql8容器远程连接不了的问题

1、进入mysql容器
docker exec -it my_mysql /bin/bash

2、登陆mysql , 选择数据库
mysql -u root -p

use mysql

3、mysql 8 设置允许远程用户访问
update user set host = '%' where user = 'root' and host='localhost'; # 更新root - localhost 为 root - %

GRANT ALL ON *.* TO 'root'@'%'; # 设置允许远程用户访问

flush privileges;# 刷新权限

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';#更新用户加密方式,mysql8默认的加密方式为caching_sha2_password 与mysql5的加密方式mysql_native_password 不同

3、Docker中可以增加参数  --default-authentication-plugin=mysql_native_password

4、K8s中可以增加参数   args: ["--default-authentication-plugin=mysql_native_password"]

猜你喜欢

转载自blog.csdn.net/zhangjunli/article/details/108650167
今日推荐