mysql8关于远程登录授权遇到的问题

问题:

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
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>

mysql> grant all on *.* to 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql>

由于对mysql不太熟悉,原因不知道,可能是版本问题。

最后新建一个test用户并授权成功,如下:

mysql> create user 'test'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.12 sec)

mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| test             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

mysql> grant all privileges on . to 'test'@'%' with grant option;
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 '. to 'test'@'%' with grant option' at line 1
mysql>
mysql> grant all on *.* to 'test'@'%';
Query OK, 0 rows affected (0.12 sec)

mysql> grant all on *.* to 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql>
mysql> flush privileges;     # 刷新权限
Query OK, 0 rows affected (0.04 sec)
mysql>

MySQL8和5的密码加密方式不同,mysql_native_password是5的加密方式。mysql已经将之前的mysql_native_password认证,修改成了caching_sha2_password认证方式。所以,使用类似于navicat或是sqlyog这些客户端时,默认使用还是mysql_native_password认证方式,所以即使输入正确的用户和密码依然登录不成功。

测试:

PS C:\WINDOWS\system32> mysql -utest -h 192.168.13.3 -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

猜你喜欢

转载自blog.csdn.net/llf_cloud/article/details/83141338