MySQL 8.0.15版本,给用户分配访问权限提示 your MySQL server version for the right syntax to use near 'IDENTIFIED...

问题描述

本想使用GRANT ALL PRIVILEGES ON *.* TO 'ZB'@'192.168.0.145' IDENTIFIED BY 'aabbccdd' WITH GRANT OPTION;命令来实现以下需求:
允许名为ZB的用户,以aabbccdd作为密码,从IP地址为192.168.0.145的主机连接到mysql服务器,并且可以访问mysql服务器的任何数据库。

报错内容如下图所示:绿色方框
image.png
the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'zhangbin' WITH GRANT OPTION' at line 1

原因

  • MySql 8.0.15没法使用GRANT ALL PRIVILEGES ON *.* TO 'ZB'@'192.168.0.145' IDENTIFIED BY 'aabbccdd' WITH GRANT OPTION;一行命令设置用户权限。
  • 必须分两步来实现设置用户权限【先创建用户、在对该用户分配用户权限】。

解决办法:我用的是授权的做法来给用户分配访问权限。

步骤一:创建用户ZB并设置密码aabbccdd。

create user 'ZB'@'192.168.0.145' identified by 'aabbccdd';

步骤二:对用户ZB分配访问权限。

GRANT ALL PRIVILEGES ON *.* TO 'ZB'@'192.168.0.145' WITH GRANT OPTION;
grant 权限列表 on 数据库 to '用户名'@'访问主机' ;

完整命令截图

/usr/local/mysql/bin/mysql -u root -p
use mysql;
select host,user from user;
create user 'ZB'@'192.168.0.145' identified by 'aabbccdd';
GRANT ALL PRIVILEGES ON *.* TO 'ZB'@'192.168.0.145' WITH GRANT OPTION;
select host,user from user;
FLUSH PRIVILEGES;
image.png

拓展1。接着上面的命令,如果你想让任何ID地址的主机都可以访问mysql服务器,那么请按如下配置。

/usr/local/mysql/bin/mysql -u root -p
use mysql;
select host,user from user;
create user 'ZB'@'%' identified by 'aabbccdd';
GRANT ALL PRIVILEGES ON *.* TO 'ZB'@'%' WITH GRANT OPTION;
select host,user from user;
FLUSH PRIVILEGES;
MySQL 8.0.15版本,给用户分配访问权限提示 your MySQL server version for the right syntax to use near 'IDENTIFIED..._第1张图片
image.png

拓展2。修改表中的host字段的值的方式来给用户分配访问权限

修改用户名为root的主机对应的host的值。改成只要名为root的用户,那么无论什么IP地址都可以访问mysql服务器。详细代码和截图如下

/usr/local/mysql/bin/mysql -u root -p
use mysql;
select host from user where user='root';
update user set host = '%' where user ='root';
select host from user where user='root';
FLUSH PRIVILEGES;
MySQL 8.0.15版本,给用户分配访问权限提示 your MySQL server version for the right syntax to use near 'IDENTIFIED..._第2张图片
image.png

你可能感兴趣的:(MySQL 8.0.15版本,给用户分配访问权限提示 your MySQL server version for the right syntax to use near 'IDENTIFIED...)