MySQL 上授予权限错误

MySQL 上授予权限错误

我是新手,从命令行管理 MySQL,通常使用 Phpmyadmin 或 MySql Workbench 来管理机器。我在尝试授予用户访问数据库的权限时遇到问题,希望得到一些帮助来解决这个问题。

    [root@server20039]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.5.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL ON *.* TO 'maintenance'@'localhost' IDENTIFIED BY 'qwerty' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

然后我尝试了这个,仍然得到同样的错误

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qwerty' WITH GRANT OPTION;

和这个

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
    IDENTIFIED BY PASSWORD 'qwerty'  
    WITH GRANT OPTION;
FLUSH PRIVILEGES;

我真的需要帮助来解决这个问题!

答案1

检查用户:

mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

检查权限:

mysql> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*03465AB87C2B44D98228458669A91479C2BAAA6C' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

如果您最近更新了 MySQL,请运行:mysql_upgrade然后重新启动 MySQL 守护程序。

相关内容