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.


  • 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 &

Incase you get an error such as the one below:

sudo mysqld_safe --skip-grant-tables --skip-networking &
[1] 3213
ubuntu@ip-172-31-17-141:~$ 2024-04-26T10:37:41.749653Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2024-04-26T10:37:41.752947Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

Proceed and create the missing directory using the command below, then rerun the previous command:

sudo mkdir -p /var/run/mysqld  

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;

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


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


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: