MySQL: grant permissions denied for CREATE

Zeno picture Zeno · May 18, 2011 · Viewed 7.3k times · Source

I setup a database & user along with grant permissions how I normally do and I'm still getting access denied and I'm not sure why:

[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)

Answer

AJ. picture AJ. · May 18, 2011

I don't believe your syntax is right. You're specifying:

GRANT ALL PRIVILEGES ON redditonrails_development.localhost

The expected syntax for db-level GRANT is: ON $db.$table. Based on this, you're only granting on the table named "localhost". Change to:

GRANT ALL PRIVILEGES ON redditonrails_development.*