今天为创建的root 用户授予相关权限提示如下错误:
mysql> grant all privileges on test.* to root@'%' identified '123456';
提示如下错误:ERROR 1064(4200): you have an error in you SQL syntax; **near 'identified '123456'' at line 1
查询MySQL8 相关授权资料的得知,分配权限不能带密码。
修改后的指令如下:
mysql > grant all privileges on test.* to root@'%'
提示的错误信息如下:You are not allowed to create a user with GRANT;
产生用户不能授权的原因是mysql 数据库中user 表中的特定用户(root) 的host 的属性值为localhost.
解决办法如下:
# 使用mysql 数据库
mysql > use mysql;
# 特定用户的host 修改
mysql > update user set host='%' where user='root';
# 指定用户的授权
mysql > grant all privileges on test.* to root@'%'