Setup: MYSQL server running on Linux
Problem: root account password is lost. You need a method to reset the password and login.
Solution:
Stop MySQL
On Debian or Ubuntu
# /etc/init.d/mysql stop or $ sudo /etc/init.d/mysql stop -- if you are not root
or on CentOS, Fedora, and RHEL:
# /etc/init.d/mysqld stop or $ sudo /etc/init.d/mysqld stop -- if you are not root
Next we need to start MySQL in safe mode.
# sudo mysqld_safe --skip-grant-tables & # mysql -u root
You should be loged in as root now, as we skipped the user privileges table.
Run these commands in mysql client:
> use mysql; > update user set password=PASSWORD("type_here_new_password") where User='root'; > flush privileges; > quit
Stop and start MYSQL
# /etc/init.d/mysql stop or $ sudo /etc/init.d/mysql stop # /etc/init.d/mysql start or $ sudo /etc/init.d/mysql start