Monday, January 21, 2013

Reset password Mysql



Hello

Today one of my client changed his mysql root password to a random one and he has actually forgot the password after that. Hence the sites started to display database error and for log in to mysql I have to reset the root password. I have done the following steps to do it

First I have stopped mysql service using the following command

#  /etc/init.d/mysqld stop

Now we need to start the mysql service without password. To start the mysql service without password you can use the --skip-gratnt-tables option. So type

#  mysqld_safe --skip-grant-tables &

Now the mysql service got started and you can Connect MYSQL server using the following command

# mysql -u root

Now mysql will not ask you for your password , you will get the MYSQL shell prompt

mysql>

Now we have to set up the new MYSQL Password for the user root
we have to use the database mysql and for that we will type the following command
mysql> use mysql;


We need to update the user set and for that we will use the following commands
mysql> update user set 

password=PASSWORD(“newrootpassword”) where user=’root’;
mysql> flush privileges;
mysql> quit
Now restart the mysql service using the following command
# /etc/init.d/mysqld restart

 Then, connect to MYSQL database using new password

# mysql -u root -p


Thats all folks Have a great day

No comments:

Post a Comment