mysql(3)-使用mysql8.x版本设置远程连接

报错grant all privileges on *.* to 'root'@'%' identified by

 

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 'root' with grant option' at line 1

mysql8中已经不支持grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option这种写法。

应该使用grant all privileges on *.* to 'root'@'%' ;

 

 1 $ /usr/local/mysql/bin/mysql -u root -p
 2 --输入密码
 3 mysql> show databases;
 4 +--------------------+
 5 | Database           |
 6 +--------------------+
 7 | information_schema |
 8 | mysql              |
 9 | performance_schema |
10 | seckill            |
11 | sys                |
12 | test               |
13 +--------------------+
14 6 rows in set (0.00 sec)
15 mysql> use mysql;
16 Reading table information for completion of table and column names
17 You can turn off this feature to get a quicker startup with -A
18 
19 Database changed
20 --查询当前数据库相关信息
21 mysql> select host,user,authentication_string,plugin from user;
22 +-----------+------------------+------------------------------------------------------------------------+-----------------------+
23 | host      | user             | authentication_string                                                  | plugin                |
24 +-----------+------------------+------------------------------------------------------------------------+-----------------------+
25 | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
26 | localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
27 | localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
28 | localhost | root             | *84AAC12F54AB666ECFC2A83C676908C8BBC381B1                              | mysql_native_password |
29 +-----------+------------------+------------------------------------------------------------------------+-----------------------+
30 4 rows in set (0.00 sec)
31 
32 --将root用户设置为所有地址可登录,原来是localhost表示只用本机可登录
33 mysql> update user set host='%' where user='root';
34 Query OK, 1 row affected (0.01 sec)
35 Rows matched: 1  Changed: 1  Warnings: 0
36 
37 --刷新权限
38 mysql> flush privileges;
39 Query OK, 0 rows affected (0.00 sec)
40 
41 --将用户root密码设置为永不过期
42 mysql> alter user 'root'@'%' identified by '12345678' password expire never;
43 Query OK, 0 rows affected (0.01 sec)
44 
45 --将root用户密码加密方式改为mysql_native_password ,上面查到root用户密码的加密方式为caching_sha2_password 
46 mysql> alter user 'root'@'%' identified with mysql_native_password by '12345678';
47 Query OK, 0 rows affected (0.00 sec)
48 
49 --刷新权限,在别的机器上即可登录
50 mysql> flush privileges;

 

 

 

 

参考文章: https://www.cnblogs.com/liran123/p/10164564.html

 

 

posted @ 2020-03-24 17:53  阳光美美哒  阅读(718)  评论(0编辑  收藏  举报