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
Release: 2024-10-29 20:50:29
Original
519 people have browsed it

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';
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template