Sunday, June 12, 2016

How to reset the Mysql root password (forget the mysql root password)

Follow the below steps to reset the mysql password.

*****************************
Step 1 : stop the mysql
*****************************
/etc/init.d/mysql stop

it will outputs 
stopping MySQL database server : mysqld

*****************************
Step 2 : starting the mysql in safemode
*****************************
run the below command to start mysql in safe mode
mysqld_safe --skip-grant-tables &

the above command outputs as
[1]5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

*****************************
Step 3 : logging to mysql
*****************************
mysql -u root 

output


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

*****************************
Step 4 : updating new password for mysql root
*****************************
  • use mysql
  • update user set password=PASSWORD("yournewpassword") where user='root';
  • flush privileges
  • quit

*****************************
Step 5 : Stop and Start the mysql
*****************************
/etc/init.d/mysql stop
/etc/init.d/mysql start

*****************************
Step 6 : login to mysql with new password
*****************************
mysql -u root -p yournewpassword

No comments:

Post a Comment