How To Reset Your MySQL or MariaDB Root Password on Ubuntu 20.04

Восстановление пароля root в mysql

MySQL is one of the most popular and widely used relational database management systems, trusted by millions of developers and organizations around the world. As with any software, there may come a time when you forget the root password for your MySQL server. However, there is no need to panic because recovering the root password in MySQL can be done relatively easily.

Before we dive into the recovery process, it is important to understand the concept of the root user in MySQL. The root user is the most privileged user in the system and has complete control over the MySQL server. Losing access to this user can be daunting, but luckily, there are various methods available to regain access to the root account.

In this article, we will explore a couple of methods that can help you recover the root password in MySQL:

1. Using the MySQL Init Scripts:
The MySQL init scripts provide a simple and straightforward way to reset the root password. Follow these steps:

1. Stop the running MySQL service using the command `sudo service mysql stop`.
2. Start the MySQL service in safe mode using the command `sudo mysqld_safe —skip-grant-tables`.
3. Open a new terminal window and log in as the root user without entering a password using the command `mysql -u root`.
4. Once you are inside the MySQL command-line prompt, switch to the MySQL database using the command `USE mysql;`.
5. Reset the root password by executing the following command: `UPDATE user SET authentication_string=PASSWORD(‘new_password’) WHERE User=’root’;`. Replace `new_password` with your desired password.
6. Flush the privileges with the command `FLUSH PRIVILEGES;`.
7. Exit the MySQL prompt using the command `QUIT;`.
8. Restart the MySQL service using the command `sudo service mysql start`.
9. Now you should be able to log in as the root user with the new password.

Дополнительно:  Силер bjm root canal sealer bjm rcs эндоканальный композитный набор шпр 5мл аксесс

2. Using the MySQL Configuration File:
If the first method didn’t work or if you are unable to stop the MySQL service, you can try this alternative method. Follow these steps:

1. Open the MySQL configuration file (`my.cnf`) using a text editor. The location of the file may vary depending on your operating system. It is generally located in `/etc/mysql/`, `/etc/`, or `/usr/local/mysql/etc/`.
2. Add the following line to the `[mysqld]` section of the configuration file: `skip-grant-tables`.
3. Save the changes and exit the text editor.
4. Restart the MySQL service using the appropriate command for your operating system (`sudo service mysql restart`, `sudo systemctl restart mysql.service`, etc.).
5. Connect to the MySQL server using the command `mysql -u root`.
6. Update the root password with the following command: `UPDATE user SET authentication_string=PASSWORD(‘new_password’) WHERE User=’root’;`.
7. Flush the privileges with the command `FLUSH PRIVILEGES;`.
8. Remove the added line (`skip-grant-tables`) from the `my.cnf` file.
9. Restart the MySQL service again.
10. You can now log in as the root user with the new password.

Remember to always keep your passwords secure and make sure to choose a strong password for your root user.

Recovering the root password in MySQL is a relatively simple process. By following the steps mentioned above, you can regain access to your MySQL server and continue with your work without any interruptions.

Оцените статью
Master Hi-technology
Добавить комментарий