1. The simplest approach to reset MySQL database root password is to execute mysql_secure_installation program and when prompted entering your new root MySQL password:
sudo mysql_secure_installation2. Let's stop the currently running MySQL database:
New password:
Re-enter new password:
sudo service mysql stop3. create a /var/run/mysqld directory to be used by MySQL process to store and access socket file:
sudo mkdir -p /var/run/mysqld4. Start manually MySQL with the following linux commands :
sudo chown mysql:mysql /var/run/mysqld
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &5. Confirm that the process is running as expected:
jobs6. Access MySQL database without password
mysql -u root7. First flush privileges MySQL session
mysql> FLUSH PRIVILEGES;8. The following commands will reset MySQL root password to "root"
mysql> USE mysql;9. Exit MySQL session:
mysql> UPDATE user SET authentication_string=PASSWORD("root") WHERE User='root';
mysql> UPDATE user SET plugin="mysql_native_password" WHERE User='root';
mysql> exit10. Terminate current mysqld process
sudo pkill mysqld11. Start MYSQL database:
sudo service mysql start12. If all went well you should now be able to login to your MySQL database with a root password:
mysql -u root --password=root
mysql> exit