MySQL连不上:ERROR 1698 (28000): Access denied for user 'root'@'localhost'

版权声明:This article is a blogger original article, only for study reference, reprint please indicate the source, thank you! https://blog.csdn.net/Rong_Toa/article/details/88543056

Table of Contents

修改文件:mysqld.cnf 

重启mysql

再次连接

修改密码

将密码方式改为常规


今天在linuxmint上安装了一个mysql

$ mysql --version
mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper

但是出现了登录不上的问题。

Failed to start mysqld.service: Unit mysqld.service not found.

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

$ systemctl start mysql 
$ mysql -uroot -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

修改文件:mysqld.cnf 

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 

 38 lc-messages-dir = /usr/share/mysql
 39 skip-external-locking
 40 #toa 2019.03.13 10:16
 41 skip-grant-tables
 42 #

重启mysql

$ service mysql restart

再次连接

$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, 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>

登陆上了,然后我quit,将上面修改后的文件注释掉

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 

 38 lc-messages-dir = /usr/share/mysql
 39 skip-external-locking
 40 #toa 2019.03.13 10:16
 41 #skip-grant-tables
 42 #

$ service mysql restart
$ mysql -uroot -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

发现又登录不上去了,然后。。。重复上面的过程,进去MySQL。

修改密码

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> update user set authentication_string=password("root ") where user="root";
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

将密码方式改为常规

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.00 sec)

mysql> update user set authentication_string=password("root "),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> 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)

mysql> exit
Bye

然后退出,将修改后的文件注释后,重启mysql。发现可以了,正常登入

$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
...
mysql> 

原文参考:https://www.cnblogs.com/cpl9412290130/p/9583868.html

猜你喜欢

转载自blog.csdn.net/Rong_Toa/article/details/88543056