A common problem with mysql databases is the loss of the root password for various reasons. This article will describe how to quickly recover a root password in mysql without losing data, using Debian/Ubuntu as an example.
Usually, when trying to run
mysql, this problem is followed by a message:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
To change the root password in mysql, log in to the root session in the console first:
Then stop the running mysql service running:
service mysql stop
After using this command:
mysqld_safe --skip-grant-tables &
you can login to mysql without a password:
mysql -uroot mysql
In the mysql session, enter the following lines:
UPDATE user SET password=PASSWORD("your_password") WHERE user="root";
Where instead of your_password – enter your new password.
After that you only need to run mysql: