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.
1 | mysql -u root -p |
Change the root password.
1 2 | ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; exit |
Login back to MySQL to test the new password.
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.
1 | systemctl stop mysql |
Run the mysql service with the –skip-grant-tables option.
1 | mysqld --skip-grant-tables --user=mysql & |
Login to MySQL.
1 | mysql |
Reload grant table.
1 | FLUSH PRIVILEGES; |
Change the root password.
1 | ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; |
Reload grant table and exit.
1 2 | FLUSH PRIVILEGES; exit |
Restart Ubuntu.
1 | reboot |
Login to MySQL using a new password.
1 | mysql -u root -p |
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin