在创建该数据库之后,无法访问某个以root用户身份的数据库

时间:2012-11-01 15:52:26

标签: mysql database root privileges grant

以root @ localhost

开头
mysql> CREATE USER 'aaa'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE ON * . * TO 'aaa'@'%' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE DATABASE IF NOT EXISTS `aaa` ;
Query OK, 1 row affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON `aaa` . * TO 'aaa'@'%';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'aaa'

发生了什么......为什么会给我这个错误?

mysql> show grants;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                                                                                                                                                                                                                                                                                                        |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*B67132C4A56F2FFFE0AA531DECF0C98895F9CB9B' WITH GRANT OPTION |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

3 个答案:

答案 0 :(得分:4)

我过去遇到过这种情况,我的解决方案是明确连接到127.0.0.1而不是localhost别名

mysql -uroot -h127.0.0.1 

希望这适合你!

答案 1 :(得分:1)

权限不够。您正尝试授予所有权限。但是,用户'root'@'localhost'没有 ALL 权限。

'SHOW GRANTS'命令输出了一系列特权 - GRANT SELECT, INSERT,...

但它应该是这样的 - GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'...

首先将所有权限授予root帐户,或者只授予未授予的权限。

答案 2 :(得分:0)

5.7中的精确度:

mysql -uroot -h127.0.0.1  -p

GRANT ALL PRIVILEGES ON *.* TO 'root';

quit

然后

mysql -u root  -h mynode mydb -p

工作正常