MySQL is an open source database software widely used for data storage. Sometimes we forgot MySQL root password. So don’t be panic, This tutorial will help you to recover MySQL root password with simple steps.
Step 1: Start MySQL in Safe Mode
To start MySQL in safe mode, first stop currently running MySQL service on your system.
# service mysql stop
Now start MySQL server in safe mode using the following command. In safe mode, MySQL does not prompt for login password.
# mysqld_safe --skip-grant-tables &
Step 2: Reset MySQL root Password
Now login to MySQL server as root user and change password using the following set of commands. It will reset MySQL root password on your system.
# mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD("NEW-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit
Step 3: Restart MySQL
After changing password stop MySQL (running in safe mode) and start it again
# service mysql stop # service mysql start
Step 4: Verify New Password
After resetting MySQL root account password and restarting, just verify new password by login.
# mysql -u root -p Enter password:
**********Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 51 Server version: 5.5.34 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql<