ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

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

2020-03-24 18:04:21  阅读:270  来源: 互联网

标签:mysql8 identified sec user mysql password root 远程


报错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

 

 

标签:mysql8,identified,sec,user,mysql,password,root,远程
来源: https://www.cnblogs.com/yiyaxuan/p/12560472.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有