How to Reset MySql User Credentials in Linux Server

mysql linux reset

This article is about how to reset MySql user credentials in linux server. In case you forgot the admin username and password of your MySql database that is running on a linux server, you can reset the root user password as follow.

First verify MySQL service is running in your linux server with this command:

sudo systemctl status mysql

Note : If the server does not have password and accessing via ssh key, make sure to use sudo.

To reset the password, we must stop mysql first. 

sudo systemctl stop mysql

Restart the MySQL service with the --skip-grant-tables option to bypass the authentication:

sudo mysqld_safe --skip-grant-tables &

Connect to MySQL as the root user without providing a password:

sudo mysql -u root

Switch to the mysql database:

use mysql;

Reset the root user password:

update user set authentication_string=password('new_password') where User='root';

After that, give privileges to root user and restart mysql

flush privileges;
exit;
sudo systemctl stop mysql
sudo systemctl start mysql

Try logging in with the new password:

sudo mysql -u root -p

Enter new password to log in.

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *