Thursday, September 17, 2009

Reset mysql root password on Linux

Reset mysql root password on Centos

  1. Stop the MySQL daemon : service mysqld stop
  2. Start MySQL in safe mode with the –skip-grant-tables and -u root options in background : mysqld_safe –skip-grant-tables -u root &
  3. Start the command line client as root : mysql -u root
  4. Issue the MySQL command to reset the root password : UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
  5. Issue the flush privileges command : FLUSH PRIVILEGES;
  6. Quit the command line tool : quit
  7. Stop the MySQL process : kill `cat /var/run/mysqld/mysqld.pid`
  8. Restart the MySQL daemon : service mysqld start
  9. Log in as root to make sure the new password is active : mysql -u root -p

Here's a screenshot so you can see how it actually goes :

reset-mysql-root-password.jpg



Set / change / reset the MySQL root password on Ubuntu . Enter the following lines in your terminal.
  1. Stop the MySQL Server.
    sudo /etc/init.d/mysql stop

  2. Start the mysqld configuration.
    sudo mysqld --skip-grant-tables &

  3. Login to MySQL as root.
    mysql -u root mysql

  4. Replace YOURNEWPASSWORD with your new password!
    UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;

Note: This method is not regarded as the securest way of resetting the password. However it works.

No comments:

Post a Comment