In the process of using the Linux operating system, we often encounter the situation of forgetting the MySQL password. What should we do at this time? This article will introduce several methods to solve this problem.
Method 1: Use mysqld_safe to start MySQL
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql
use mysql; update user set password=PASSWORD("new_password") where User='root'; flush privileges;
The "new_password" is the new password you want to set. After the setting is successful, you can use the quit command to exit MySQL, and then use the following command to restart the MySQL service.
sudo /etc/init.d/mysql restart
Method 2: Use the dpkg-reconfigure command
sudo /etc/init.d/mysql stop
sudo dpkg-reconfigure mysql-server-5.5
The option to reset the MySQL password will appear.
sudo /etc/init.d/mysql restart
It should be noted that the dpkg-reconfigure command is only valid on Debian systems.
Method 3: Use the MySQL management tool
In addition to the above two methods, you can also use the MySQL management tool to reset the MySQL password. Here are two commonly used MySQL management tools.
sudo apt-get install phpmyadmin
sudo apt-get install mysql-workbench
To use the MySQL management tool to reset the password, you need to provide the user name and password of the MySQL administrator. Before resetting your password, make sure you have backed up your MySQL database.
To sum up, forgetting MySQL password is not a troublesome problem and can be solved by the above methods. Before operating, be sure to back up the database to avoid losing important data.
The above is the detailed content of Forgot mysql password in linux. For more information, please follow other related articles on the PHP Chinese website!