«

mysql8开启远程访问(适用于docker/k8s)

myluzh 发布于 阅读:861 MySQL


0x01 开启mysql远程访问

如果存在 Host='%' 的记录 → 允许所有IP远程访问
如果只有 Host='具体IP' → 仅允许特定IP访问
如果无结果 → 禁止远程访问

mysql> SELECT User, Host FROM mysql.user WHERE Host != 'localhost';
+------+------+
| User | Host |
+------+------+
| root | %    |
+------+------+
1 row in set (0.00 sec)

mysql -u root -p 进去

-- 更新root - localhost 为 root - %
update user set host = '%' where user = 'root' and host='localhost';

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

-- 刷新权限
flush privileges;

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

0x02 Docker/K8s配置

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

mysql8 远程访问


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/mysql/161.html
文章标题:《mysql8开启远程访问(适用于docker/k8s)