ref: mysql lost password, how to change it?

ref:https://www.linuxidc.com/Linux/2007-05/4338.htm

mysql "Access denied for user 'root'@'localhost'" problem solving

# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Use the method introduced on the Internet to modify the password of the root user:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

Now I finally found a solution, as follows (please first Test method three, thank you!):

Method one:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <Enter the new password newpassword>

mysql>show databases;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325949478&siteId=291194637