You've managed to forget your root login for your MySQL database and are now stuck? No worries, I will show you in easy steps, how to reset
root password on MySQL database.
Remember this: MySQL root password is not the same as the system root password. If you haven't set a root password for MySQL during first installation, or right after it, it's most likely it's empty as MySQL doesn't require password for database connections. However, it is recommended you set a password yourself. Just for security reasons.
What should you do to reset MySQL root password, is:
1. Login as root to your machine and stop the MySQL server daemon.
$ su Passowrd: # /etc/init.d/mysql stop
2. Start the MySQL server without a password.
# mysqld_safe --skip-grant-tables &
- Connect to MySQL server with MySQL client.
# mysql -u root
- Set a new MySQL root user password by entering the following four commands. Be sure to change
NEWROOTPASSWORDto your desired password.
mysql> use mysql; mysql> update user set password=PASSWORD('DESIRED_ROOT_PASSWORD') where User='root'; mysql> flush privileges; mysql> quit
- Stop MySQL server (it's running in safe mode).
# /etc/init.d/mysql stop
- And start MySQL server.
# /etc/init.d/mysql start
- Test to make sure new MySQL root password works.
# mysql -u root -p