Resetting MySQL root password

Resetting MySQL root password


First Stop mysql using your teminal

sudo /etc/init.d/mysql stop

To resolve this issue, you can follow these steps:

  1. Create the directory for the MySQL UNIX socket file:

    sudo mkdir -p /var/run/mysqld

  2. Change the ownership of the directory to the MySQL user:

    sudo chown mysql:mysql /var/run/mysqld

  3. Start the MySQL service with the --skip-grant-tables and --skip-networking options:

    sudo mysqld_safe --skip-grant-tables --skip-networking &

    This command should start the MySQL service without performing any privilege checks and without enabling network connections.

Once the MySQL service is running, you can proceed with resetting the root password or performing any necessary recovery steps.

  1. Stop the MySQL server:

    sudo service mysql stop

  2. Start the MySQL server with the --skip-grant-tables option:

    sudo mysqld_safe --skip-grant-tables &

  3. Open a new terminal window and log in to the MySQL server as the root user:

    mysql -u root

  4. In the MySQL prompt, switch to the MySQL database:

    USE mysql;

  5. Reset the root password:

    UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';

    Replace 'new_password' with your desired password.

  6. Flush the privileges to apply the changes:

    FLUSH PRIVILEGES;

  7. Repeat step 5 after flushing the pivileges

  8. Exit the MySQL prompt:

    EXIT;

  9. Stop the running MySQL server:

    sudo service mysql stop

  10. Start the MySQL server again:

    sudo service mysql start

After following these steps, your root password should be reset to the new password you specified. Make sure to replace 'new_password' with your desired password in step 5.

June 1, 2023, 6:34 p.m. | Authored by Mugoya Dihfahsih

0 Comments

create username To join the discussion