How to reset root user password in MySQL 5.7+

Was too busy and haven’t written anything for quite a while!

Anyway, here is how to reset the root user password in MySQL 5.7 and later in a nutshell!

service mysql stop
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysqld_safe --skip-grant-tables &
mysql

mysql> UPDATE mysql.user SET authentication_string=PASSWORD('new-password') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

mysqladmin -u root -p shutdown
service mysql start

That’s it, Enjoy!

Sources:

Unknown's avatar

About Ahmed Tawfik

Cybersecurity Professional, Systems Engineer, OSS & Linux Geek
This entry was posted in Linux, MySQL and tagged , , , , . Bookmark the permalink.

Leave a comment