It is only common to forget the database password. However, we can recover MySQL database server password following five easy steps.
- First step is to stop the MySQL server process.
$> sudo /etc/init.d/mysql stop
- Start the MySQL (mysqld) server/daemon process with the
--skip-grant-tables
option so that it will not prompt for the password.
$> sudo mysqld_safe --skip-grant-tables &
- Then, connect to mysql server as the root user.
$> mysql -u root
- Now that we’re in as the root user, setup new mysql root account password i.e. reset mysql password.
- Finally, exit and restart the MySQL server.
$> sudo /etc/init.d/mysql stop $> sudo /etc/init.d/mysql start $> mysql -u root -p
mysql> use mysql; mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit
With this we would’ve successfully changed the password.