Home Linux Tutorial Reset MySQL Password on Rocky Linux 9 and Fix Access Denied for...

Reset MySQL Password on Rocky Linux 9 and Fix Access Denied for User ‘root’@’localhost’

If you’ve encountered the dreaded “Access Denied for User ‘root’@’localhost'” error when trying to access MySQL, fear not! We’ll guide you through the steps to reset your MySQL password on Rocky Linux 9. Follow these simple instructions to regain access to your MySQL server.

Step 1: Locate the MySQL Configuration File

Firstly, you’ll need to locate the mysql.cnf file. This file might be stored in different locations depending on your system setup.

  • /etc/my.cnf
  • /etc/mysql/my.cnf

If you’re unsure about its location, you can search your MySQL installation folder. For instance, on Windows or Mac, look for the file there. If you can’t find it, don’t worry; you can create one in the /etc folder.

Step 2: Edit the Configuration File

Open the my.cnf file using a text editor of your choice. Look for the [mysqld] section, and add the following line beneath it.

[mysqld] 

skip-grant-tables

Step 3: Restart MySQL Server

Once you have made this change, restart the MySQL server to apply the new configuration.

# sudo systemctl restart mysqld

Step 4: Access MySQL

Now, you can log in to MySQL using the root account.

Note: HIT ENTER WITHOUT PASSWORD.

mysql -u root -p

Once logged in, execute the following command to flush privileges.

FLUSH PRIVILEGES;

Step 5: Set a New Password

Next, set a new password for the root account using the following command.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';

Replace ‘your_new_password’ with your desired secure password.

Step 6: Revert Configuration Changes

Open the my.cnf file again, and remove the line skip-grant-tables that you added earlier. Save the file after making this change.

Step 7: Restart MySQL Server Again

Once you have reverted the configuration changes, restart the MySQL server again.

# sudo systemctl restart mysqld

Step 8: Verify Access

Finally, log in to the root account one more time.

mysql -u root -p

You should now be able to log in successfully with your new password without encountering any errors.

By following these steps, you’ve successfully reset the MySQL password on Rocky Linux 9 and resolved the ‘Access Denied’ issue for the root user.

Video Tutorial

A big thank you for exploring TechsBucket! Your visit means a lot to us, and we’re grateful for your time on our platform. If you have any feedback or suggestions, we’d love to hear them. Looking forward to serving you again soon!

LEAVE A REPLY

Please enter your comment!
Please enter your name here