zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Ajax省市区无刷新单表联动查询
    Hadoop2.0、YARN技术大数据视频教程
    零基础DNET B/S开发软件工程师培训视频教程
    零基础DNET CS开发视频教程
    HTML5开发框架PhoneGap实战视频教程
    Web前端开发视频教程
    FluentData 轻量级.NET ORM持久化技术详解
    前端 MVVM 框架KnockOut.JS深入浅出视频教程
    ASP.NET Web开发项目实战视频教程
    零基础到CS开发高手通用权限管理系统全程实录
  • 原文地址:https://www.cnblogs.com/yiyaxuan/p/12560472.html
Copyright © 2011-2022 走看看