MySQL 登入資料庫報錯'ERROR 1045 (28000): Access denied for user'..'@'localhost''

feelpurple發表於2017-03-04
登入資料庫時報錯
[root@localhost install]# mysql -uzabbix -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)

檢視資料庫中的使用者
[root@localhost install]# mysql -uroot -p
mysql> select host,user from mysql.user;
+-----------------------+--------+
| host                  | user   |
+-----------------------+--------+
| %                     | zabbix |
| 127.0.0.1             | root   |
| localhost             |        |
| localhost             | root   |
| localhost.localdomain |        |
| localhost.localdomain | root   |
+-----------------------+--------+
6 rows in set (0.00 sec)

報錯原因:
在user授權表中,zabbix使用者被賦予了在所有主機登入的許可權,但是沒有在localhost的登入許可權;在MySQL中,localhost的登入需要使用socket的方式,而其他的登入則使用-h指定IP或主機名的方式

解決方法:
使用-h透過IP登入即可
[root@localhost install]# mysql -h 10.10.10.10 -uzabbix -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> select user();
+--------------------+
| user()             |
+--------------------+
| zabbix@10.10.10.10 |
+--------------------+
1 row in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2134697/,如需轉載,請註明出處,否則將追究法律責任。

相關文章