Home >Database >Mysql Tutorial >How to Force-Reset MySQL Root Password When Access is Denied?

How to Force-Reset MySQL Root Password When Access is Denied?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-29 20:50:29544browse

How to Force-Reset MySQL Root Password When Access is Denied?

Force-Resetting the MySQL Root Password Despite Access Denial

You've encountered an issue where you're unable to log in as root, preventing you from changing the MySQL root password.

One effective approach to force-reset the root password involves creating a file containing the following SQL statement:

UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';

Save this file with an appropriate name, such as "resetPassword.sql."

Next, execute the following command to manually start MySQL with the file you created as the initialization file:

mysqld --init-file=resetPassword.sql

Once the MySQL server starts, it will execute the SQL statement from the file, resetting your password.

After executing the file, shut down the server and restart it normally:

service mysqld stop
service mysqld start

You should now be able to log in as root with the new password you provided in the SQL statement.

The above is the detailed content of How to Force-Reset MySQL Root Password When Access is Denied?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn