解决在linux中配置MySQL8远程授权的时候出现ERROR 1410 (42000): You are not allowed to create a user with GRANT
在Linux下的MySQL8中,以前的 grant all privileges on . to ‘root’ @‘%’ identified by ‘root’;
授权方法不能用了。
用以下方法:
1.创建
输入:create user root identified by ‘123’; //新建用户时没有指定主机,则默认为%。
以上的是创建一个用户,root是用户,123是密码。
2.授权
输入: grant select on test.* to root; //授权时没有指定主机,也是默认为%。
这一步是为它授权。 root是用户。
3.刷新
最后记得刷新
flush privileges;
例如:
1.mysql> create user user11 identified by '123'; //新建用户时没有指定主机,则默认为%
Query OK, 0 rows affected (0.00 sec)
2.mysql> grant select on test.* to user11; //授权时没有指定主机,也是默认为%
Query OK, 0 rows affected (0.00 sec)
4.注:防火墙问题以及远程连接密码加密规则问题
1.centOS7下关闭防火墙与centOS6及之前的命令有所不同:
centOS7的命令:
systemctl stop firewalld
centOS6及之前的命令:
service iptables stop
2.mysql8远程连接数据库工具:
新版本在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password。
所以通过命令行方式将加密方式改回老版的方式。
- use mysql;
- 查看当前加密方式:
select user,plugin from user where user=‘root’;
当前用户的加密方式为caching_sha2_password,我们要改成mysql_native_password
-
修改加密方式
首先需要查看自己root用户的host是什么
select user,host from user;
-
然后根据host修改:
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
加粗的地方需要修改为自己的host名和密码。
-
最后刷新权限就可以成功连接了。
flush privileges;