3

作为 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)
4

3 回答 3

5

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

mysql -uroot -h127.0.0.1 

希望这对你有用!

于 2012-11-01T15:55:37.160 回答
1

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

'SHOW GRANTS' 命令已输出权限列表 -GRANT SELECT, INSERT,...

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

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

于 2012-11-01T16:22:58.377 回答
1

5.7 中的一点精度:

mysql -uroot -h127.0.0.1  -p

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

quit

然后

mysql -u root  -h mynode mydb -p

工作正常

于 2017-03-03T13:32:18.843 回答