Reset root password on MySQL

Start MySQL server without user authentication and networking, this allows to connect without credentials from localhost only. Run using the same user account the MySQL daemon runs under to avoid permission problems (probably, sounds reasonable doesn’t it?)

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

Connect to MySQL with no credentials:


Reload authentication:


Change root password:

MySQL 5.7.6 and later:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

From here:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.