How to reset root user password by using command line

Hi All,

I am using MySQL database in Linux environment.
And I forget root user password of MySQL database.
I want to know how to reset the root user password by using command line Linux environment.
So please help me to reset the password by using the command line.

Hi Sachin,

Try these commands.

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root mysql

in mysql prompt:

update user set password=PASSWORD(“newpassword”) where User=‘root’;
flush privileges;
exit
/etc/init.d/mysql start

Hi Sashi,

Thanks for you reply.
I tried your solution but that is not work in my case.

PFA.

Use sudo and try once again, it should work…

Hi Sashi,

Thanks dude.

Its work but there is one more problem when I was updating root password error occur.

Hi,

I forget my root password and I want to reset.

What version of Linux are you using? You will have to boot into single user mode and remount the file system as rw and change the password there.

It seems he wants to reset his mysql root password, use sudo for all the commands you give, it will work.