Force Resetting MySQL Root Password
Encountering difficulties logging in with the root user and altering the password in MySQL Server can be frustrating. This guide provides a solution to resolve this issue on Red Hat Linux.
Issue:
The user is unable to connect to MySQL as the root user and receives an access denied error. Even common methods such as using mysqladmin and resetting the password using the --skip-grant-tables option do not yield success.
Solution:
To resolve this problem, utilize the following approach:
Locate and create a file named 'reset-root-password.sql' with the following content:
<code class="sql">UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';</code>
Start the MySQL server with the --init-file flag, specifying the created file as the argument:
mysqld_safe --init-file=reset-root-password.sql
Once the server is up and running, connect to MySQL using the root user and the newly set password:
mysql -u root -p Enter password: newpass
Shut down the server and restart it normally:
mysqladmin -u root -p shutdown mysqld_safe
After completing these steps, you should be able to log in to the MySQL server as the root user and utilize the password you defined.
The above is the detailed content of How to Force Reset the MySQL Root Password on Red Hat Linux?. For more information, please follow other related articles on the PHP Chinese website!