MySQL:为 CREATE 授予权限被拒绝
Posted
技术标签:
【中文标题】MySQL:为 CREATE 授予权限被拒绝【英文标题】:MySQL: grant permissions denied for CREATE 【发布时间】:2011-08-28 05:10:49 【问题描述】:我像往常一样设置了数据库和用户以及授予权限,但我仍然被拒绝访问,我不知道为什么:
[root@server23 redditonrails]# mysql -u redditonrails -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 431954
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use redditonrails_development;
Database changed
mysql> create table test;
ERROR 1142 (42000): CREATE command denied to user 'redditonrails'@'localhost' for table 'test'
mysql> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for redditonrails@localhost |
+------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'redditonrails'@'localhost' IDENTIFIED BY PASSWORD '*******' |
| GRANT ALL PRIVILEGES ON `redditonrails_test`.`localhost` TO 'redditonrails'@'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails_development`.`localhost` TO 'redditonrails'@'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails`.`localhost` TO 'redditonrails'@'localhost' |
+------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> SELECT USER(),CURRENT_USER();
+-------------------------+-------------------------+
| USER() | CURRENT_USER() |
+-------------------------+-------------------------+
| redditonrails@localhost | redditonrails@localhost |
+-------------------------+-------------------------+
1 row in set (0.00 sec)
【问题讨论】:
另外,您可能希望在创建表时添加一列。可能是这样... 刚试了,没修。 mysql> 创建表测试(id INT); ERROR 1142 (42000): CREATE command denied to user 'redditonrails'@'localhost' for table 'test' 【参考方案1】:我不相信你的语法是正确的。您正在指定:
授予所有权限
redditonrails_development
.localhost
db 级 GRANT 的预期语法为:ON $db.$table
。基于此,您只授予名为“localhost”的表。改为:
授予所有权限
redditonrails_development
.*
【讨论】:
【参考方案2】:您的用户 redditonrails 似乎拥有所有特权
redditonrails_development
.localhost
这意味着redditonrails_development
数据库和localhost
表。你想要的就是在那里
redditonrails_development
.*
witch 意味着您在所有表上都拥有所有特权(甚至是您尝试创建的新表)
至少我是这么看的。
【讨论】:
以上是关于MySQL:为 CREATE 授予权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章
Firebase 安全规则完全打开,但仍然授予权限被拒绝错误