MySQL8 root用户远程访问配置 Allow root user remote access.

发布于 作者 量尺寸留下评论

首先配置MySQL 8 使其能允许任意IP访问,以下操作均是在需要管理员权限 sudo

nano /etc/mysql/mysql.conf.d/mysqld.cnf

将 bind-address 设置为 0.0.0.0

bind-address = 0.0.0.0

重新启动mysql服务

systemctl restart mysql

这时我们需要设置root用户权限。其中 host=’%’ 是指任意IP均可访问,%可换成任意IP,此时代表root用户仅可通过此IP访问MySQL。

mysql -uroot -p

use mysql;

update user set host=’%’ where user=’root’;

flush privileges;

exit;

如果MySQL是 –skip-grant-tables 选项模式运行的,会提示如下:

“The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement”

这时我们需要按以下方法进行操作:

mysql> set global read_only=0;

mysql> flush privileges;

然后再次设置:

mysql> set global read_only=1;

flush privileges;

通过以上操作就可以使root用户远程登录MySQL服务器。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注