Home  >  Article  >  Database  >  How to Reset MySQL Root Password When Access Denied and Traditional Methods Fail?

How to Reset MySQL Root Password When Access Denied and Traditional Methods Fail?

Susan Sarandon
Susan SarandonOriginal
2024-10-30 12:00:27187browse

How to Reset MySQL Root Password When Access Denied and Traditional Methods Fail?

How to Reset the MySQL Root Password When Access Denied

This issue arises when attempting to log in to MySQL as the root user proves unsuccessful due to access denial. Subsequently, attempts to set or reset the password using mysqladmin or the --skip-grant-tables method fail.

To overcome this challenge, consider the following alternative:

Save the following SQL statement into a file:

<code class="sql">UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';</code>

Manually start the MySQL server using the following command:

mysqld --init-file=FILENAME

Replace FILENAME with the name of the file containing the SQL statement.

Upon server startup, the password should be reset to 'newpass.'

Next, shut down the server and restart it normally. You should now be able to log in with the new password.

The above is the detailed content of How to Reset MySQL Root Password When Access Denied and Traditional Methods Fail?. 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