mysql登錄錯誤ERROR 1698 (28000)

之前MySQL服務端本機上使用密碼登陸root賬號是沒有問題的,但是今天不知道是動了哪里,登陸失敗并有這個錯誤代碼:

# mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

解決步驟:

停止mysql服務

#  service mysql stop

以安全模式啟動MySQL

# sudo mysqld_safe --skip-grant-tables &

MySQL啟動之后就可以不用密碼登陸了

# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 Server version: 5.7.10 MySQL Community Server (GPL)

查看一下user表,錯誤的起因就是在這里, root的plugin被修改成了auth_socket,用密碼登陸的plugin應該是mysql_native_password。

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,plugin from user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.01 sec)

關于auth_socket,在官方有說明: https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.html ,反正現(xiàn)在暫時不用它, 那就把這里改了。

>mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

改完之后

mysql> select user,plugin from user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | mysql_native_password |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)

重啟服務,問題就解決了

root@localhost:~# service mysql restart
 * Stopping MySQL database server mysqld       
2019-09-23T16:01:39.843922Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
                                                                                                [ OK ]
 * Starting MySQL database server mysqld   No directory, logging in with HOME=/
                                                                                                [ OK ]
[1]+  Done                    mysqld_safe --skip-grant-tables
root@localhost:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21-1ubuntu1 (Ubuntu)

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容