How to Reset MySQL Root Password and Access phpMyAdmin in Safe Mode

Blog

Forgetting the MySQL root password can be frustrating, but don’t worry—there’s a way to reset it without requiring the old password. This guide will walk you through the process of starting MySQL in safe mode and resetting the root password, allowing you to log into phpMyAdmin easily. Follow these steps to regain access.

1. Stop the MySQL Service

Before making any changes, you need to stop the MySQL service. Open your terminal and run the following command:

sudo systemctl stop mysql

2. Start MySQL in Safe Mode

Next, you’ll need to start MySQL in safe mode, bypassing the authentication system by skipping the grant tables.

Run the command:

sudo mysqld_safe --skip-grant-tables &

If you encounter an error such as:

mysqld_safe Directory '/var/run/mysqld' for UNIX socket file doesn't exist.

You need to create the missing directory and set the appropriate permissions.

Create the Necessary Directory:

Run the following commands to create the directory and assign the correct ownership and permissions:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo chmod 755 /var/run/mysqld

3. Access phpMyAdmin Without a Password

Once MySQL is running in safe mode, you can now access phpMyAdmin without needing a password.

  • Open your browser and go to the phpMyAdmin login page.
  • Log in as root without entering a password.

4. Update the Root Password

Once inside phpMyAdmin, follow these steps to reset the root password:

  1. Navigate to the mysql database.
  2. Open the user table.
  3. In the authentication_string column, update hashed password for click here to download
  4. In the plugin column, ensure it’s set to caching_sha2_password.

After Updated hashed password, Now new root password will be: coder@123.

5. Restart MySQL After Resetting the Password

Now that you’ve updated the password, it’s time to restart MySQL properly.

Stop the MySQL Safe Mode:

If MySQL is still running in safe mode, you’ll need to kill the process.

sudo killall mysqld

Then, stop MySQL:

sudo systemctl stop mysql

6. Try Logging In Again

With the MySQL service back to normal and the password reset, you can now try logging in with the new password:

mysql -u root -p 

Enter coder@123 when prompted for the password, and you should now have access.


By following these steps, you should be able to regain access to your MySQL server through phpMyAdmin, reset the root password, and start using MySQL again.

In this video, we’ll walk you through the step-by-step process to create dynamic subdomains and install a wildcard SSL certificate on a VPS server. Learn how to configure DNS settings, set up Nginx for handling wildcard subdomains, and secure your site with Let’s Encrypt SSL using Certbot. Perfect for anyone looking to set up subdomains dynamically and secure them in 2024. Whether you’re a beginner or an experienced developer, this tutorial will guide you through creating secure, scalable subdomains on your VPS server!

Leave a Reply

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