How to Reset MySQL root password when lost

0
1073

when a MySQL server is running but root access has lost somehow and require to reset root access, are is the simple solution.

first stop the running MySQL server.

/etc/init.d/mysql stop

now run the MySQL server by skipping grant table so that MySQL can be accessed from localhost without password, to do this run below command :

/usr/bin/mysqld_safe --skip-grant-tables &

now connect MySQL server without password :

mysql --user=root mysql

and set the password for MySQL root :

update user set Password=PASSWORD('Set_Pasword_here') WHERE User='root';

flush privileges;

exit

now start the MySQL process with grant table again.

/etc/init.d/mysql start

LEAVE A REPLY