Ubuntu18.04:mysql:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘

Install mysql on Ubuntu:

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

Encountered an error when logging in:

mysql -u root -p

Solution:

Enter sudo vim /etc/mysql/mysql.conf.d/mysqld.cnfinto the mysql configuration file:

Add skip-grant-tables after skip-external-locking, save and exit.

终端执行 service mysql restart, Restart mysql.

终端执行mysql -u root -p, Prompt to enter the password and press Enter. After entering mysql, execute the following three sentences:

use mysql;
update user set authentication_string=PASSWORD('新密码') where user='root';
flush privileges;

Then enter quitand exit mysql.

Re-enter the mysqld.cnf file and sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf,comment out the skip-grant-tables statement added at the beginning.

Then return to the terminal mysql -u root -pand enter the password you just set.

 

Guess you like

Origin blog.csdn.net/whuzhang16/article/details/109258781