Restoring MySQL Root Password
When you encounter access denied errors for the root user, resetting the password becomes imperative. Here's a stepwise guide for resetting the root password in MySQL:
Stop MySQL Server:
Use the following command on FreeBSD:
sudo stop mysql
Start MySQL with Grant and Networking Restrictions Bypassed:
Execute the below command:
sudo mysqld --skip-grant-tables --skip-networking
Connect to MySQL as Root:
Issue the command:
mysql
Update Root Password:
Enter the following statement:
update mysql.user set password = password('your_new_password') where user = 'root';
Flush Privileges:
Use this command:
flush privileges;
Exit MySQL:
Type:
exit;
Stop and Start MySQL Server:
Run these commands:
sudo mysqladmin shutdown sudo start mysql
You should now be able to log in as root with the new password you have assigned. Reference the provided link for further details: http://snippets.dzone.com/posts/show/13267.
The above is the detailed content of How Can I Reset My MySQL Root Password?. For more information, please follow other related articles on the PHP Chinese website!