Resetting MySQL Root Password Without Old Password
If you find yourself unable to recall your MySQL root password, regaining access is possible through a series of steps.
To begin, stop the MySQL service using the command:
sudo service mysql stop
Next, start MySQL in safe mode with the following command:
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
In a new terminal, connect to MySQL as root:
mysql -u root
Execute the following queries to change the root password:
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
Note: In MySQL 5.7, the password field was replaced by the authentication_string field.
Finally, quit MySQL safe mode and restart the MySQL service:
mysqladmin shutdown sudo service mysql start
With these steps, you should have reset your MySQL root password successfully.
The above is the detailed content of How to Reset MySQL Root Password Without the Old Password?. For more information, please follow other related articles on the PHP Chinese website!