LLI Wiki — My Digital Knowledge Base

Resetting the root password on older MySQL versions

Procedure to reset the MySQL root password on version 5.6 and earlier using --skip-grant-tables, only on a server you administer.

This procedure resets the root password on MySQL releases that store the password in the password column of mysql.user, that is MySQL 5.6 and earlier. Use it only on a server you administer. While the server runs with --skip-grant-tables, any local user can connect without a password, so stop the server in the normal way when you are done.

  1. Stop the server.

    /etc/init.d/mysql stop
    
  2. Start it without loading the grant tables and without network access.

    mysqld_safe --skip-grant-tables --skip-networking &
    
  3. Open the mysql database and set the new root password.

    mysql mysql
    
    UPDATE user SET password = PASSWORD('NEW_PASSWORD') WHERE user = 'root' AND host = 'localhost';
    
  4. Shut the server down.

    mysqladmin shutdown
    
  5. Start the server normally, then test the new password.

    /etc/init.d/mysql start
    mysql -u root -p
    

Notes

Mastodon LLIMastodon SocialFosstodon