In this article we are going to learn the steps of “Reset MySQL 5.7 Root password on Ubuntu 22.04 LTS”.

Introduction

Losing or forgetting the root password for your MySQL 5.7 server on Ubuntu 22.04 LTS can be a frustrating situation. However, you can reset the MySQL root password with a few straightforward steps. In this tutorial, we’ll guide you through the process of resetting the MySQL 5.7 root password on your Ubuntu 22.04 LTS server.

Prerequisites

  • A server running Ubuntu 22.04 LTS.
  • MySQL 5.7 installed on the server.

Steps of Reset MySQL 5.7 Root Password on Ubuntu 22.04 LTS

Let’s start the steps to reset the 5.7 root password on ubuntu 22.04 LTS server.

Step #1: Stop the MySQL Service

Before you can reset the root password, you need to stop the MySQL service. Open a terminal and enter the following command:

ubuntu@Rushi-InfoTech:~$ sudo service mysql stop

Step #2: Make MySQL Service directory with write permission

  • Make MySQL service directory.
ubuntu@Rushi-InfoTech:~$ sudo mkdir /var/run/mysqld
  • Give MySQL user permission to write to the service directory.
ubuntu@Rushi-InfoTech:~$ sudo chown mysql: /var/run/mysqld

Step #3: Start MySQL in Safe Mode

Now, start MySQL in safe mode to bypass the password authentication. Use the following command to launch MySQL in safe mode:

ubuntu@Rushi-InfoTech:~$ sudo mysqld_safe --skip-grant-tables --skip-networking &

This command will start MySQL without requiring a password, and it won’t allow network connections for security reasons.

Step #4: Access MySQL as Root

Next, you need to access the MySQL server as the root user without a password. Open a new terminal window and run the following command:

ubuntu@Rushi-InfoTech:~$ mysql -uroot mysql

This will log you into the MySQL server.

Step #5: Change MySQL Root Password

Please Execute following command:

mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';

Flush the privileges.

mysql> FLUSH PRIVILEGES;

In the MySQL shell, use the following SQL command to reset the root password. Replace ‘Rushi@159’ with your desired new password:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Rushi@159';

Replace ‘Rushi@159’ with your chosen password within single quotes.

Step #6: Flush Privileges and Exit

After changing the password, flush the privileges to update the changes and exit the MySQL shell:

mysql> FLUSH PRIVILEGES;
mysql> exit

Stop the MySQL safe mode instance:

ubuntu@Rushi-InfoTech:~$ sudo killall -u mysql

If you see any MySQL output with ended message hit ‘ENTER’ to continue.

Step #8: Start MySQL Service

Start the MySQL service:

ubuntu@Rushi-InfoTech:~$ sudo service mysql start

Step #9: 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

Enter the new password when prompted, and you should have access to the MySQL server.

Conclusion

In this tutorial, you learned how to reset MySQL 5.7 root password on Ubuntu 22.04 LTS server. By following these steps, you can regain access to your MySQL database even if you’ve forgotten the root password, ensuring the security and functionality of your MySQL server.

For Reference:

To know about MySQL pls visit official Website.

Any queries pls contact us @Rushi-InfoTech

Similar Posts

Leave a Reply

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