Tag Archives: Mysql:ERROR 1698 (28000): Access denied for user ‘root’@’localhost’

Mysql:ERROR 1698 (28000): Access denied for user ‘root’@’localhost’

What are the eight life cycle hook functions of Vue>>>

Description

Scenario: this problem usually occurs after the installation of MySQL

Reason: when using the command sudo apt get install MySQL to install, there is no prompt to enter the password, then the password is not initialized, and the login with root user naturally fails

Details:

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

Here’s how to solve the problem

Solutions

Idea: since the password is not initialized, you can log in directly with the default password

The steps are as follows:

1. Use the cat command to view the default user name and password

sudo cat /etc/mysql/debian.cnf 

Contents displayed:

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = HwPMmIAFg1GNU0OH
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = HwPMmIAFg1GNU0OH
socket   = /var/run/mysqld/mysqld.sock

2. Log in with the default user name and password

mysql -udebian-sys-maint -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
……
mysql>

Login successful
3. Modify plugin settings (this is the reason for this problem)

UPDATE mysql.user SET authentication_string=PASSWORD('root'), PLUGIN='mysql_native_password' WHERE USER='root';

Setup complete
4. Restart the service

/etc/init.d/mysql stop
/etc/init.d/mysql start

5. Login

mysql -uroot -p

At this point, you can successfully log in

Attached

Sometimes there are some strange problems in MySQL. In many cases, in order to save time, you choose to reload and attach the reload process

Uninstall completely

sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

Installation

sudo apt-get update
sudo apt-get install mysql-server

Complete the operation

Conclusion

thank you for reading, welcome to correct the problems in the blog, you can also contact me, make progress and communicate with me

WeChat official account: the dog
mail box: [email protected]
personal blog: http://roobtyan.cn
scan the QR code below and follow me, you will get something unexpected…

My blog will be synchronized to Tencent cloud + community. I invite you to join us: https://cloud.tencent.com/developer/support-plan