本文分析了mysql登陸報錯提示:ERROR 1045 (28000)的解決方法。分享給你們供你們參考,具體以下:mysql
1、問題:linux
公司linux系統的mysql數據庫root用戶設置過密碼,但經常用命令'mysql -u root -p'登陸報錯,有時又能登陸。登陸報錯信息爲:sql
1
2
3
|
[root@localhost ~]
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied
for
user
'root'
@
'localhost'
(using password: YES)
|
2、緣由:數據庫中存在空用戶所致數據庫
3、解決方法:vim
一、停用mysql服務:bash
1
|
# service mysql stop
|
二、輸入命令:dom
1
|
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
|
或ui
cd /etc/mysql/conf.d/
vim mysqld.cnf
cd /etc/mysql/mysql.conf.d/
vim mysqld.cnf
重啓 service mysql restart
三、登入數據庫:spa
1
|
# mysql -u root mysql
|
四、.net
1
|
mysql> use mysql;
|
五、
1
|
mysql>
select
user,host,password from user;
|
結果以下:
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | % | mima |
| root | localhost.localdomain | mima |
| root | 127.0.0.1 | mima |
| | localhost | |
| | localhost.localdomain | |
+------+-----------------------+----------+
六、將上面查詢出來的空用戶刪除:
1
|
mysql> delete from user where user=
''
;
|
七、退出數據庫:
1
|
mysql> quit
|
八、啓動mysql服務:
1
|
# service mysql start
|
九、從新用命令:
1
|
mysql -u root -p
|