mysql授予sql脚本让用户无法正常工作

时间:2014-06-12 14:58:31

标签: mysql sql

标题说明了一切,这是我的代码

GRANT SELECT, INSERT, UPDATE, DELETE ON 'database_name' TO 'mysqluser'@'111.111.111.111';

它说

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 near ''database_name' TO 'mysqluser'@'111.111.111.111'' at line 1

2 个答案:

答案 0 :(得分:2)

此:

GRANT SELECT, INSERT, UPDATE, DELETE ON 'database_name' TO 'mysqluser'@'111.111.111.111';

应该是:

GRANT ALL ON 'database_name'.* TO 'mysqluser'@'111.111.111.111';

在您的特定情况下(在我的mysql服务器上测试):

GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'mysqluser'@'111.111.111.111';

答案 1 :(得分:1)

您使用'引用了数据库名称,将其转换为字符串。一旦它成为一个字符串,它就不再是一个表名。它只是一个包含看起来像表名的东西的字符串。

应该是EITHER

GRANT ... ON database_name
or
GRANT ... ON `database_name`

只有在db名称恰好是保留字时才需要反引号。