Reset MySQL root password in Ubuntu

To recover or reset MySQL root password in Ubuntu, you should simply follow some steps. This process may vary according to the operating system. Ubuntu offerts a possibility to restore the root password via dpkg, which is a native package management system.

Recovering the database root access: reset MySQL root password in Ubuntu

First, we need to stop the MySQL server:

Now we will run dpkg-reconfigure , to reset the mysql password:

It will prompt for the new password, just like in the new installation of MySQL. You must type the new password in this screen.

reset mysql root password in ubuntu

Now, restart the MySQL server

Now you will be able to login using the new mysql root password:

Change a MySQL user password

To change an user password, you must have the current MySQL root password. You should follow these steps we will explain. In these examples we will use localhost , for local users connecting from the same server. If the user is authorized to connect remotely, we would have to replace it with its IP address.

There is an alternative method. You can also change the password directly in the mysql users table:

The expected success output is:

Afterwards, you must flush privileges, so that the changes take effect:

Afterwards, you can exit mysql, and try to login with the new defined user password:

If you happen to use root from an external host or IP, you should  reset mysql root password manually. Just change [user-name] by root and specify the IP address authorized for the root user.

This tutorial applies either for a cheap dedicated server with Ubuntu, or for a vps hosting Ubuntu server.

Leave a Reply

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