Thursday, February 16, 2017



MySQL root password recovery


You can recover MySQL database server root password following below six easy steps:
  1. Stop the MySQL server process:
    1. /etc/init.d/mysqld stop
  2.  Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password:
    1.  mysqld_safe --skip-grant-tables &
    2.  /etc/init.d/mysqld start
  3.  Connect to mysql server as the root user:
    1.  mysql -u root
  4.  Setup new mysql root account password i.e. reset mysql password:
    1. mysql> use mysql;
    2. Change root password (read all 3 below before issuing commands):
      1. MySQL 5.7.6 and later: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
      2. MySQL 5.7.5 and earlier: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); 
      3. Or for any MySQL version: update user set Password=PASSWORD('MyNewPass') where User='root';
    3. mysql> flush privileges;
    4. mysql> quit 
  5. Exit and restart the MySQL server:
    1.  /etc/init.d/mysqld restart
  6.  Connect to MySQL and verify if new root password is accepted:
    1. mysql -u root -p

No comments:

Post a Comment