December 25, 2013 · admin database debian linux mysql security server system

MySQL root password reset

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 
# /etc/init.d/mysql stop

2. Start the MySQL server without a password.

# mysqld_safe --skip-grant-tables &
  1. Connect to MySQL server with MySQL client.
# mysql -u root
  1. Set a new MySQL root user password by entering the following four commands. Be sure to change NEWROOTPASSWORD to your desired password.
mysql> use mysql; 
mysql> update user set password=PASSWORD('DESIRED_ROOT_PASSWORD') where User='root'; 
mysql> flush privileges; 
mysql> quit
  1. Stop MySQL server (it's running in safe mode).
# /etc/init.d/mysql stop
  1. And  start MySQL server.
# /etc/init.d/mysql start
  1. Test to make sure new MySQL root password works.
# mysql -u root -p
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket