问题简述:MySQL 8执行授权语句报语法错误
遇到问题的时间:2021-09-08
我的MySQL 8的版本:Server version: 8.0.26
我安装完MySQL8数据库后,有以下几个需求:
下面是我的操作步骤:
(1)创建scene数据库
mysql> CREATE DATABASE scene;
Query OK, 1 row affected (0.01 sec)
(2)创建scene用户,指定密码为123456
mysql> CREATE USER 'scene'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.13 sec)
(3)给用户授予对scene数据库的所有操作权限
但是竟然报错了!!!
报了一个SQL语法错误,这个授权语句在MySQL 5.7中是能正常执行的,但是在MySQL 8中就报错喽。
mysql> GRANT ALL PRIVILEGES ON scene.* TO 'scene'@'%' 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
(4)解决方案
把IDENTIFIED BY '123456'这个语句删掉,再次执行,就执行成功了。
mysql> GRANT ALL PRIVILEGES ON scene.* TO 'scene'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.08 sec)