In this article we will cover the steps to reset mysql 8 root password on ubuntu 20.04 LTS. So please follow the steps carefully and in order to make the process easier and smooth.
Introduction:
MySQL is a widely-used relational database management system. If you’ve forgotten the root password for your MySQL 8 installation on Ubuntu 20.04 LTS, don’t worry; we’ll walk you through the steps to reset it.
Prerequisites:
Before you begin, make sure you have:
- Access to a terminal on your Ubuntu 20.04 LTS server.
- Sudo privileges or access to the root user account.
Steps of “How to Reset MySQL 8 Root Password on Ubuntu 20.04 LTS?”
Let’s start the steps to Reset MySQL 8 Root Password on Ubuntu 20.04 LTS. Please follow steps in order.
Step #1: Stop MySQL Service
Before resetting the MySQL root password, stop the MySQL service:
ubuntu@Rushi-InfoTech:~$ sudo systemctl stop mysql
![](https://rushiinfotech.in/wp-content/uploads/2023/09/2-copy-24-1024x66.png)
Step #2: Start MySQL in Safe Mode
Start MySQL in safe mode, which allows you to bypass authentication and make changes to user accounts:
ubuntu@Rushi-InfoTech:~$ sudo mysqld_safe --skip-grant-tables --skip-networking &
![](https://rushiinfotech.in/wp-content/uploads/2023/09/3-copy-20-1024x149.png)
Hit ‘ENTER’ to return to your terminal.
Step #3: Access MySQL
Connect to the MySQL server without a password:
ubuntu@Rushi-InfoTech:~$ sudo mysql -u root mysql
![](https://rushiinfotech.in/wp-content/uploads/2023/09/4-copy-23-1024x351.png)
You successfully entered into the mysql database without password.
Step #4: Change MySQL Root Password
Please Execute following command:
mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
![](https://rushiinfotech.in/wp-content/uploads/2023/09/5-copy-17-1024x84.png)
Flush the privileges.
mysql> FLUSH PRIVILEGES;
![](https://rushiinfotech.in/wp-content/uploads/2023/09/6-copy-18-1024x60.png)
In the MySQL shell, use the following SQL command to reset the root password. Replace ‘Rushi@123’ with your desired new password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Rushi@123';
![](https://rushiinfotech.in/wp-content/uploads/2023/09/7-copy-13-1024x64.png)
Replace ‘Rushi@123’ with your chosen password within single quotes.
Step #5: Flush Privileges and Exit
After changing the password, flush the privileges to update the changes and exit the MySQL shell:
mysql> FLUSH PRIVILEGES;
![](https://rushiinfotech.in/wp-content/uploads/2023/09/8-copy-6-1024x60.png)
mysql> exit
![](https://rushiinfotech.in/wp-content/uploads/2023/09/9-copy-14-1024x81.png)
Step #6: Stop MySQL Safe Mode
Stop the MySQL safe mode instance:
ubuntu@Rushi-InfoTech:~$ sudo killall -u mysql
![](https://rushiinfotech.in/wp-content/uploads/2023/09/10-copy-19-1024x141.png)
If you see any MySQL output with ended
message hit ‘ENTER’ to continue.
Step #7: Start MySQL Service
Start the MySQL service:
ubuntu@Rushi-InfoTech:~$ sudo systemctl start mysql
![](https://rushiinfotech.in/wp-content/uploads/2023/09/11-copy-15-1024x59.png)
Step #8: Verify New Password
To confirm that the root password has been successfully reset, try logging in with the new password:
ubuntu@Rushi-InfoTech:~$ mysql -u root -p
![](https://rushiinfotech.in/wp-content/uploads/2023/09/12-copy-9-1024x322.png)
Enter the new password when prompted, and you should have access to the MySQL server.
Conclusion:
In this guide, we’ve demonstrated how to reset the MySQL 8 root password on Ubuntu 20.04. Losing access to your database can be a challenging situation, but by following these steps, you can regain control and secure your MySQL installation with a new root password.
Remember to keep your new password secure, as it grants full access to your MySQL database server. This process ensures that you can maintain control and security over your MySQL database, even in situations where the root password is lost or forgotten.
For Reference:
To know about MySQL pls visit official Website.
Any queries pls contact us
https://rushiinfotech.in/contact/