You are currently viewing How to Reset MYSQL root Password

How to Reset MYSQL root Password

Losing or forgetting the MySQL root password can be a haunting situation. In this article, we walk you through the steps to reset MySQL root password on an Ubuntu system.

Prerequisites

  • Access to the Ubuntu system where MySQL is installed.
  • Basic knowledge of the terminal and MySQL.

How to Reset MYSQL root user Password

Steps to Reset MySQL Root user Password

1. Stop the MySQL Server

Stop the MySQL server to prepare for the password reset:

sudo systemctl stop mysql

2. Start MySQL in Safe Mode

Start MySQL in safe mode, which allows us to reset the root password without authentication:

sudo mysqld_safe --skip-grant-tables --skip-networking &

3. Access MySQL without a Password

Open a new terminal window and connect to MySQL as the root user without a password:

mysql -u root
USE mysql;
FLUSH PRIVILEGES;

4. Set a New Root Password

Run the following SQL commands to set a new password for the root user:

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

5. Exit MySQL and Restart the MySQL Server

Exit from MYSQL

EXIT;

Then stop the running mysqld_safe process:

sudo pkill mysqld

Start the MySQL server normally:

sudo systemctl start mysql

6. Verify the New Password

Having set a new root password, login in with the new password.

mysql -u root -p  #Enter new password on prompt

Conclusion

You have successfully reset the root password. If MySQL was installed without a prompt to enter a root password, use this method to set a new password.

Make a donation to support us



Web Hosting and email hosting Packages


For web development services, SEO services, Digital marketing strategies, website set up services, web hosting and domain registration; contact Dynamic Technologies.


Related content: