Lost MySQL Admin Password

I lost mysql admin (root user) password. How do I reset a lost MySQL admin (root) password under UNIX or Linux or BSD operating systems?

Type the following commands. First, stop current MySQL database server:
/etc/init.d/mysql stop
OR
/etc/init.d/mysqld stop
OR
/usr/local/etc/rc.d/mysql-server stop

Now, start mysql server without password so that you can restart the password:
mysqld_safe --skip-grant-tables &
Login without a password, enter:
mysql -u root
Finally, setup a new MySQL root user password, enter::

USE mysql;
UPDATE USER SET password=PASSWORD("NEW-ROOT-PASSWORD") WHERE USER='root';
FLUSH privileges;
quit

use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User=’root’;
flush privileges;
quit

Replace NEW-ROOT-PASSWORD with actual password you want to use. Restart running mysql server:
/etc/init.d/mysql restart
Test it:
mysql -u root -p

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.