Wednesday 20 March 2013

Mysql change/recover root password

If you already know the root password you can just update it using
# mysqladmin -u root -p oldpassword newpassword


If you forgot root password and need to restore, it can be done easily with following steps

Step # 1: Stop the MySQL server process.

# /etc/init.d/mysql stop or Kill mysqld and if exists mysqld_safe processes.



Step # 2: Start the MySQL (mysqld) daemon process with the --skip-grant-tables option.

# mysqld_safe --skip-grant-tables &
This option will enable us to login to database without root password.

Step # 3: Connect to mysql server as the root user (No password would be needed)

# mysql -u root

Step # 4: Setup new mysql root account password and flush privileges.

mysql> update mysql.user set password=PASSWORD("newrootpassword") where User='root';
mysql>flush privileges;
mysql>\q

Step # 5: Exit and restart the MySQL server.
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Now login using new password
# mysql -u root -p

No comments:

Post a Comment