MySQL密碼正確卻無法本地登錄 報錯如下: ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 解決方法:1、在啟動mysql的參數中加入跳過密碼問題方式,如下:vim /etc/m ...
MySQL密碼正確卻無法本地登錄
報錯如下:
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
解決方法:
1、在啟動mysql的參數中加入跳過密碼問題方式,如下:
vim /etc/my.cnf
併在[mysql]下麵加上skip-grant-tables,
這個用於跳過密碼問題,但是這並不能徹底解決。
2、重啟mysql服務
本人用的是Linux系統的Mysql,語句如下:
查看埠號:
ps aux|grep mysqld
查看狀態:
systemctl status mysqld
重啟mysql服務
systemctl restart mysqld
嘗試連接:
mysql -uroot -p123456
輸入密碼,剛纔已經設置跳過密碼了可忽略
操作步驟如下:
[root@localhost ~]# mysql -uroot -p123456
mysql> use mysql
Database changed
mysql> select user,host,password from user where user='root';
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | % | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | ::1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.02 sec)
mysql> update user set host='localhost' where user='root' and host='%';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
OK,退出mysql,重啟mysql就解決問題了
前後對比一下:
[root@localhost ~]# mysql -uroot -p
mysql> use mysql;
Database changed
mysql> select user,host,password from user where user='root';
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| root | ::1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql>
OK!
gook luck!