How to Change Your MySQL Password in Ubuntu 14.04

If you would like to reset the password for the root  user’s MySQL password, this guide will help you through that process. 

Reset MySQL Password

Stop the MySQL Server

You will want to have the correct version before continuing with this guide and are able to get it using this command:

Before continuing with the following, you will want to know that these steps are intended to be run by the root user by using su or sudo commands. Logging in as your root user is not recommended.

In order to change the MySQL password, you will need to first stop the MySQL service.

If you know your password, you can change it using MySQL command line with the following for the root user in this example

mysql -u root -p
Replace new_password above with your new password.

By running MySQL without loading any information about the user privileges, you can access the command line without using root privileges which would require a password.  You can do this by not allowing the database to load the grant tables.  You’ll also want to skip networking in order to avoid any security risks. 

It is important to note that using --skip-networking  below is very insecure and should only be run while resetting the root  user’s password if you have forgotten it.

Start the MySQL command prompt using this command: 

You’ll now be able to access the database without using the root password. 

A MySQL command prompt will appear:

You can now change the password and will want to remain in the MySQL command prompt.

 

Changing The Password

You will first want to use the FLUSH PRIVILEGES command. 

Now we can actually change the root password and exit the MySQL command line by pressing CTRL + C to exit.

You can then use one of the below commands to change your password based on the version of MySQL you are using.

 

For MySQL 5.7.6 and newer use the following command in the MySQL command prompt.

 

For MySQL 5.7.5 and older use in the MySQL command prompt:

Enter your new password above and replace new_password .

Once you have received message that the query was OK, you can Flush Privileges 

 

Restart the MySQL Server

Now you will need to start the service. 

You can now confirm that the password reset worked by running the following command:

Share:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.