1.登录mysql
mysql -uroot -p
2.选择进入mysql数据库
use mysql
3.在mysql数据库的 user 表中查看当前 root 用户的相关信息
这里可以看到root默认显示是localhost,只支持本地访问,不支持远程。
select host, user, authentication_string, plugin from user;
4.修改mysql的root用户远程访问权限
update user set host='%' where user='root';
再次查看mysql数据库的user表中root用户信息,可以看到修改完之后为%。
select host, user, authentication_string, plugin from user;
5.修改mysql加密规则
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
刷新权限
flush privileges;
6.使用Navicat测试连接
参考:数据库8.0设置远程访问