How to change MySQL root password
In case you forgot your MySQL root password, this article will show you how to reset the MySQL root password from the command line.
To change MySQL root password (version 8 & further) follow the below steps :-
NOTE: The mentioned steps are performed on CentOS 7 server.
1. Identify the Server Version.
mysql --version
2. Stop MySQL service.
sudo systemctl stop mysql
3. Start the MySQL server without loading the grant tables.
sudo mysqld --skip-grant-tables --user=mysql &
4. Log in to the MySQL shell.
mysql -u root
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
5. Stop Mysql server.
mysql -u root
6. Kill this process running for “mysqld –skip-grant-tables –user=mysql &” command..
sudo ps aux | grep mysqld
kill -9 pid
6. Start MySQL server.
sudo systemctl start mysqld
8. Verify the password.
mysql -u root -p
You will be prompted to enter the new root password. Enter it, and you should be logged in to your database server.
Leave a Reply