Recently I had lost the root password to one of my dedicated servers due to a harddrive crash and all scripts and backups lost (don’t ask).
So I had to dig around the mysql user notes and I figured out how to kind of reset the mysql root pass. Here it is:
Login as root, then stop the mysql server daemon and restart it in safe mode so that MySQL doesn’t read the Grant tables anymore, thus bypassing the currently set password:
[root@myserver]# /etc/init.d/mysql.server stop
/usr/local/mysql/bin/safe_mysqld –user=mysql –skip-grant-tables –skip-networking &
With that done, use the mysqladmin tool to set a new root password as follows (I’m setting the new MySQL root password to “newrootpass”:
/usr/local/mysql/bin/mysqladmin -u root flush-privileges password “newrootpass”
Next, restart the daemon for MySQL:
[root@myserver]# /etc/init.d/mysql.server restart
Use your root password as you normally would for MySQL!