Resetting MySQL root password on newer MySQL 5.7

In newer versions of MySQL it looks like the ‘Password’ field has been replaced with the ‘authentication_string’ field so older instructions online may not work.

Stop the currently running MySQL service:

systemctl stop mysql

Start mysql skipping permissions tables:

mysqld_safe --skip-grant-tables

Then in another terminal run the mysql client:

mysql

Then the following SQL:

UPDATE mysql.user SET authentication_string = PASSWORD('opensesame'), password_expired = 'N'  WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
quit

Return to the first terminal and Crtl-c to end the mysqld_safe process. Then start the normal service:

systemctl start mysql

Try logging in as root again with the new password:

mysql -u root -popensesame

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>