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 mysql_safe --skip-grant-tables --skip-networking &

Connect to MySQL with no credentials:

$ mysql

Reload authentication:

mysql> FLUSH PRIVILEGES;

Change root password:

MySQL 5.7.6 and later:

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

MySQL 5.7.5 and earlier:

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

From here: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

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