ERROR 1045 (28000): Access denied for user 'root'@'localhost'
一、錯誤描述:
錯誤如標題:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。我用root@localhost授權登陸,然後給其中
一個使用者授權,然後報如上錯誤:
[mysql@centos6-clone ~]$ mysql -u root -p
Enter password:
Your MySQL connection id is 2
Server version: 5.6.25-log MySQL Community Server (GPL)
mysql> grant all on *.* to 'fi'@'127.0.0.1' identified by "fi";
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql> exit
Bye
按理來說,root@localhost是最高許可權。居然不能給其他人授權。1045錯誤是授權拒絕。怎麼辦?
二、錯誤分析
檢視下root許可權:
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
我們看root@localhost 有許可權:ALL PRIVILEGES,但是沒有WITH GRANT OPTION 語句,就是別人授權的許可權。所以,不能授權的原因是:
沒有這個WITH GRANT OPTION 語句。
三、錯誤解決
知道原因了,解決問題就很簡單了。用另外一個方式登入root@127.0.0.1,然後給root@localhost授權,這樣root@localhost 就可以給其他使用者
授權了。
[mysql@centos6-clone ~]$ mysql -uroot -p -h127.0.0.1
Enter password:
mysql> SHOW GRANTS
-> ;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@127.0.0.1 |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
[mysql@centos6-clone ~]$ mysql -uroot -p
Enter password:
mysql> grant all on *.* to 'fo'@'%' identified by "fo";
Query OK, 0 rows affected (0.00 sec)
錯誤如標題:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。我用root@localhost授權登陸,然後給其中
一個使用者授權,然後報如上錯誤:
[mysql@centos6-clone ~]$ mysql -u root -p
Enter password:
Your MySQL connection id is 2
Server version: 5.6.25-log MySQL Community Server (GPL)
mysql> grant all on *.* to 'fi'@'127.0.0.1' identified by "fi";
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql> exit
Bye
按理來說,root@localhost是最高許可權。居然不能給其他人授權。1045錯誤是授權拒絕。怎麼辦?
二、錯誤分析
檢視下root許可權:
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
我們看root@localhost 有許可權:ALL PRIVILEGES,但是沒有WITH GRANT OPTION 語句,就是別人授權的許可權。所以,不能授權的原因是:
沒有這個WITH GRANT OPTION 語句。
三、錯誤解決
知道原因了,解決問題就很簡單了。用另外一個方式登入root@127.0.0.1,然後給root@localhost授權,這樣root@localhost 就可以給其他使用者
授權了。
[mysql@centos6-clone ~]$ mysql -uroot -p -h127.0.0.1
Enter password:
mysql> SHOW GRANTS
-> ;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@127.0.0.1 |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
[mysql@centos6-clone ~]$ mysql -uroot -p
Enter password:
mysql> grant all on *.* to 'fo'@'%' identified by "fo";
Query OK, 0 rows affected (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30393770/viewspace-2122687/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Error 1045(28000) Access Denied for user 'root'@'localhost'Errorlocalhost
- Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- 解決Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:YES)Errorlocalhost
- 報錯”ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”Errorlocalhost
- ERROR 1045 (28000): Access denied for userError
- ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)Errorlocalhost
- Linux錯誤 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)LinuxErrorlocalhost
- 解決Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)的方法MySqlErrorlocalhost
- MySQL 8.0.13 密碼問題 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)MySql密碼Errorlocalhost
- #1045 - Access denied for user 'root'@'localhost' (using password: NO)localhost
- ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)Error127.0.0.1
- mysql 1045, "Access denied for user 'root'@'localhost' (using password: NO)"MySqllocalhost
- linux安裝MySQL出現ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)LinuxMySqlErrorlocalhost
- MySQL 登入資料庫報錯'ERROR 1045 (28000): Access denied for user'..'@'localhost''MySql資料庫Errorlocalhost
- mysql ERROR 1045 (28000): Access denied for user解決方法MySqlError
- Ubuntu18.04:mysql:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘UbuntuMySqlErrorlocalhost
- 【MySQL】---1045-Access denied for user 'root'@'localhost'(using password :YES)MySqllocalhost
- MYSQL解決error: 'Access denied for user 'root'@'localhost' (using password:MySqlErrorlocalhost
- MySQL使用普通使用者訪問返回ERROR 1698 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- ubuntu mysql Access denied for user root@localhostUbuntuMySqllocalhost
- Access denied for user 'root'@'localhost' (using password: NO)localhost
- 解決mysql“Access denied for user 'root'@'localhost'”MySqllocalhost
- rhel4 mysql5.1登陸ERROR 1045 (28000): Access denied for userMySqlError
- Access denied for user ‘root‘@‘localhost‘問題的解決localhost
- Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解決方式MySqlCentOSlocalhost
- 解決mysql"Access denied fot user 'root'@'localhost'"問題MySqllocalhost
- 登入mysql報ERROR 1045 (28000): Access denied 解決方法MySqlError
- vue專案中連線MySQL時,報錯ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password:YES)VueMySqlErrorlocalhost
- Mysql 5.5 原始碼安裝後建立使用者報錯"ERROR 1045 (28000): Access denied for user"MySql原始碼Error
- 啟動報錯:Access denied for user 'root'@'localhost' (using password:YES)localhost
- java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: YES)JavaSQLExceptionlocalhost
- ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'ErrorlocalhostDatabaseMySql
- ERROR 1044 (42000): Access denied for user 'root'@'%' to databaseErrorDatabase
- SQLSTATE[HY000] [1045] Access denied for user ‘root‘@‘localhost‘ (using password: YES)”錯誤的隱藏解決辦法SQLlocalhost
- SpringBoot中yml配置java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: NOSpring BootJavaSQLExceptionlocalhost
- MySQL系列:Docker安裝 MySQL提示錯誤:Access denied for user'root'@'localhost' (using password:yes)MySqlDockerlocalhost
- mac os x 安裝mysql遇到 Access denied for user ‘root‘@‘localhost‘ (using password: YES)的解決方法MacMySqllocalhost