Home > Database > Mysql Tutorial > How to Force Reset the MySQL Root Password on Red Hat Linux?

How to Force Reset the MySQL Root Password on Red Hat Linux?

Linda Hamilton
Release: 2024-10-29 07:27:30
Original
327 people have browsed it

How to Force Reset the MySQL Root Password on Red Hat Linux?

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:

  1. Open a terminal emulator and navigate to the MySQL installation directory.
  2. 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>
    Copy after login
  3. Start the MySQL server with the --init-file flag, specifying the created file as the argument:

    mysqld_safe --init-file=reset-root-password.sql
    Copy after login
  4. Wait for the server to start. This process may take some time.
  5. 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
    Copy after login
  6. Shut down the server and restart it normally:

    mysqladmin -u root -p shutdown
    mysqld_safe
    Copy after login

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!

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