grant 命令报错

问题描述:使用grant给用户授权的时候,报1064的错
Mysql 版本mystl8.0

  1. mysql> grant all privileges on testdb.* to hxy@"%" identified by "hxy";
  2. 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 "hxy"' at line 1

报错原因:mysql8 不再支持使用grant命令显示的创建用户,在mysql8中可以这样使用grant命令

  1. mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
  2. mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
  3. mysql> FLUSH PRIVILEGES;

参考链接:stackoverflow:how-to-grant-all-privileges-to-root-user-in-mysql-8-0