MySQL8.0 或 MySQL5.7给root用户赋予远程连接权限(Windows)

参考博客

问题

直接使用grant all privileges on *.* to 'root'@'%' with grant option;给root用户赋予可远程连接权限时报错

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '123456' WITH GRANT OPTION' at line 1

解决

# 选中mysql数据库
use mysql;

# 修改库中user表中,user用户的host=%(任意连接)
update user set host='%' where user ='root';

# 重新加载权限表
flush privileges;

# 给root用户赋予远程连接权限
grant all privileges on *.* to 'root'@'%' with grant option;

测试, 成功。

你可能感兴趣的:(后端相关,数据库)