mysql8开启远程访问(适用于docker/k8s)
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"]