How to Change and Reset MySQL 8 Root Password on Ubuntu 18.04

MySQL database has a root user who is the main user or administrator who can configure and have access to all databases. Very often there are cases of wanting to change the root password for example because it changed the system administrator. In the case of a password reset, it’s usually because you forgot the root password. Well, in this tutorial I will discuss about how to change and reset the MySQL 8 password on Ubuntu 18.04.

*Change Password*

Change the root password here means that we can still log in using the root user, we still know the password, but want to change the password.

Login to MySQL with the root user.

[INPUT]

1 mysql -u root -p

Change the root password.

[INPUT]

1 2 ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password’; exit

Login back to MySQL to test the new password.

[INPUT]

1 mysql -u root -p

*Password Reset*

Reset password here means we forget or don’t know the root password, so you have to reset or forced change the password.

Stop mysql service.

[INPUT]

1 systemctl stop mysql

Run the mysql service with the *–skip-grant-tables* option.

[INPUT]

1 mysqld –skip-grant-tables –user=mysql &

Login to MySQL.

[INPUT]

1 mysql

Reload grant table.

[INPUT]

1 FLUSH PRIVILEGES;

Change the root password.

[INPUT]

1 ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password’;

Reload grant table and exit.

[INPUT]

1 2 FLUSH PRIVILEGES; exit

Restart Ubuntu.

[INPUT]

1 reboot

Login to MySQL using a new password.

[INPUT]

1 mysql -u root -p

Good luck 🙂

Leave a Reply

Your email address will not be published.