×

Reset MySQL Root Password on Red Hat Enterprise Linux 8 - Step by Step Process ?

This article covers how to reset or change your MySQL root password on Red Hat Enterprise Linux 8.

MySQL is an open source relational database management system (RDBMS) with a client-server model for creating and managing databases based on a relational model.


To Reset the MySQL root password:

You must run the commands in the following steps as the root user. 

Therefore, you can either log in directly as the root user (which is not recommended for security reasons), or use the su or sudo commands to run the commands as the root user.

To reset the root password for MySQL, follow these steps:

1. Log in to your account using SSH.

2. Stop the MySQL server using the appropriate command for your Linux distribution:

For CentOS and Fedora, type:

$ service mysqld stop

For Debian and Ubuntu, type:

$ service mysql stop

3. Restart the MySQL server with the —skip-grant-tables option. To do this, type the following command:

$ mysqld_safe --skip-grant-tables &

4. Log into MySQL using the following command:

$ mysql

5. At the mysql> prompt, reset the password. To do this, type the following command, replacing new-password with the new root password:

UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';

6. At the mysql> prompt, type the following commands:

FLUSH PRIVILEGES;
exit;

7. Stop the MySQL server using the following command.

You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

$ mysqladmin -u root -p shutdown

8. Start the MySQL server normally. To do this, type the appropriate command for your Linux distribution:

For CentOS and Fedora, type:

$ service mysqld start

For Debian and Ubuntu, type:

$ service mysql start






Keep In Touch