问题说明:
- 在8.0以前,我们习惯使用以下命令授权远程连接操作:
grant all privileges on *.* to 'root'@'%';
- 但在8.0以后,使用以上命令会报错:
ERROR 1410 (42000): You are not allowed to create a user with GRANT
分析原因:
因为在8.0以后,这个特性已被移除,官方文档如下:
原文:Using GRANT to modify account properties other than privilege assignments. This includes
authentication, SSL, and resource-limit properties. Instead, establish such properties at account-creation
time with CREATE USER or modify them afterward with ALTER USER.
译文:使用grant修改账户权限分配以外的账户属性。包括认证,SSL,和资源限制配置等。取而代之的是创建用户create user或者创建后修改alter user的方式。
解决方案:
- 使用以下命令可以成功,但无法远程登陆:
grant all on *.* to 'root'@'localhost';
- 此时,可以使用以下2种方式,实现远程:
-- 1. 使用update user
update user set host='%' where user ='root';
-- 2. 使用create user
create user 'userName'@'%' identified by 'your_password';