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.
-
Stop the server.
/etc/init.d/mysql stop -
Start it without loading the grant tables and without network access.
mysqld_safe --skip-grant-tables --skip-networking & -
Open the
mysqldatabase and set the new root password.mysql mysqlUPDATE user SET password = PASSWORD('NEW_PASSWORD') WHERE user = 'root' AND host = 'localhost'; -
Shut the server down.
mysqladmin shutdown -
Start the server normally, then test the new password.
/etc/init.d/mysql start mysql -u root -p
Notes
- From MySQL 5.7.6, passwords are stored in the
authentication_stringcolumn, and thepasswordcolumn no longer exists. For those versions, follow the password reset statements of the MySQL documentation for your release, includingALTER USER. - The restart in step 5 loads the grant tables again, so no
FLUSH PRIVILEGESis needed after step 3.