How to Reset MySQL Root User Password on Ubuntu

Websolutionstuff | Jan-26-2024 | Categories : Other

Hey there! If you've ever found yourself scratching your head over a forgotten MySQL root password on Ubuntu, fear not – I've got your back. In this guide, I'll walk you through the steps to reset that password like a pro.

Now, don't worry if you're not a command-line expert. We're going to take it one step at a time, and by the end of this, you'll be back in control of your MySQL root access.

So, grab your Ubuntu terminal, and let's dive into the world of resetting passwords together. Ready? Let's get started!

So, let's see how to reset the MySQL root user password on Ubuntu, how to change the MySQL root user password in Ubuntu, change the MySQL root password in Ubuntu, and reset the mysql root password on Ubuntu 23.04.

Here's a step-by-step guide on how to reset the MySQL root user password on Ubuntu:

Step 1: Open Terminal

Open a terminal on your Ubuntu system. You can do this by pressing Ctrl + Alt + T or searching for "Terminal" in the application launcher.

 

Step 2: Stop MySQL Service

Before resetting the password, stop the MySQL service to prevent any potential conflicts. Use the following command:

sudo service mysql stop

 

Step 3: Start MySQL in Safe Mode

Start MySQL in safe mode, skipping the grant tables to avoid loading user privileges. This allows you to reset the root password without authentication.

sudo mysqld_safe --skip-grant-tables &

 

Step 4: Connect to MySQL

Open a new terminal window and connect to the MySQL server without entering a password:

mysql -u root

 

Step 5: Select MySQL Database

Switch to the mysql database, where user information is stored:

use mysql;

 

Step 6: Update Root Password

Now, update the root user password with the following command. Replace 'new_password' with your desired password

UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';

If you are using MySQL 8.0 and later versions, use the following command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

 

Step 7: Flush Privileges

Flush the privileges to apply the changes:

FLUSH PRIVILEGES;

 

Step 8: Exit MySQL

Exit the MySQL shell:

exit;

 

Step 9: Stop and Start MySQL Service

Stop the MySQL service started in safe mode:

sudo service mysql stop

Then, start the MySQL service:

sudo service mysql start

 

Step 10: Verify the New Password

Try logging into MySQL using the new password to ensure it's working:

mysql -u root -p

Enter the new password when prompted.

 

Conclusion

You've successfully reset the MySQL root user password on Ubuntu! This can be handy if you ever find yourself locked out or need to update your password for security reasons.

 


You might also like:

Recommended Post
Featured Post
Laravel 9 whereDate And whereMonth Query Example
Laravel 9 whereDate And whereM...

In this article, we will see laravel 9 wheredate() and wheremonth() query examples. The whereDate me...

Read More

Oct-19-2022

How to Install PHP Soap Extension in Ubuntu 23.04
How to Install PHP Soap Extens...

Hey fellow developers! Today, let's tackle the installation of the PHP SOAP extension on our Ubuntu 23.04 systems. I...

Read More

Jan-31-2024

The Mix Manifest Does Not Exist Laravel
The Mix Manifest Does Not Exis...

In this article, we will see the mix manifest does not exist in laravel 8 and laravel 9. We will solve the mix...

Read More

Oct-28-2022

How to Install and Configure Elasticsearch on Ubuntu
How to Install and Configure E...

Hey there! Today, I'm going to walk you through the process of installing and setting up Elasticsearch on your Ubunt...

Read More

Jan-08-2024