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