Resetting MySQL password (mysql 5.7.21) on Ubuntu

February 20th, 2018

1. Stop MySQL

service mysql stop

2. Create the stuff mysql deletes when it quits

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

3. Start MySQL in safe mode

sudo /usr/sbin/mysqld –skip-grant-tables –skip-networking &

4. Log in MySQL prompt

mysql -uroot

5. Update root password

update user set authentication_string=password(“new_password”) where user=”root”;

6. Reload the GRANT tables

flush privileges;

7. Exit


8. Stop service

service mysql stop

9. Start service

service mysql start

10. Log back in with new password

mysql -u root -p

Leave a Reply

Your email address will not be published. Required fields are marked *