MySql 在没有明显错误的情况下创建用户时出现语法错误

MySql syntax error during user creation when there is no apparent error

我正在尝试使用以下指南使用 Ubuntu 安装 Moodle:Ubuntu 分步安装指南

我目前在第 6 步,我必须创建一个具有正确权限的 mySQL 用户,这就是我遇到的问题。

第一个命令 - create user 'user1'@'localhost' IDENTIFIED BY 'password1'; 工作正常

但是第二个命令-

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO user1@localhost
IDENTIFIED BY 'password1';

Returns 错误信息 - 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 'password1'' at line 1

安装手册提到这可能是一个问题,所以建议我使用 - SELECT password('password1'); 以获得哈希值来解决这个问题。

然而,它没有给我一个哈希值,而是出现了相同的错误 - 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 '('password1')' at line 1

我是这一切的初学者,所以我很感激任何回复,提前致谢!

您需要在命令中的名称和主机周围加上撇号,例如:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'user1'@'localhost'
IDENTIFIED BY 'password1';

编辑

根据评论,稍微更改命令修复了语法错误:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'user1'@'localhost';

首先创建用户'moodleuser'@'localhost',由'yourpassword'标识;

然后 grant select,insert,update,delete,create,create temporary tables,drop,index,alter on moodle.* to 'moodleuser' @'localhost';