jump to navigation

How to Change Mysql root Password August 24, 2011

Posted by Tournas Dimitrios in Mysql.

It may happen , you forgot the password of your Mysql databases server (local development) . There is no way to recover a lost database password , for security reasons , it’s stored as md5-hash sum (algorithm) in the database . The best way to change the lost password is to  update the credentials with new values .  This quick article shows how to update your Mysql server’s root password via the terminal on a Linux box (CentOs) .The process is the same on all *nix like operating systems .

  • Open a terminal window with root privileges .
  • Stop the MySQL server process .
    sevice mysqld  stop 
  • Start the MySQL (mysqld) daemon process in safe-mode with the – -skip-grant-tables option so that it will not prompt for a password . Force the server-daemon to start in background , so you don’t have to open a new terminal window .
    mysqld_safe  – -skip-grand-tables  &
  • Connect to the server without password
    mysql  -uroot
  • Switch to mysql table :  use mysql
  • Change the password
    update user set password=PASSWORD(“your-new-pass”) where User=’root’ ;
  • Enable changes :  flush privileges ;
  • Exit the mysql client mode :  exit ;
  • Stop the database daemon :
    service mysqld stop
  • Start the database daemon is normal mode
    service mysqld start
  • Now login with mysql-client as usual
    mysql  -uroot  -p   
  • It will ask your password … and …….you are in …..


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s