How I fixed my MySQL crapped out with ERROR 1045 (28000): Access denied for user ‘root’@’localhost’

Once in a while MySQL dies. Several reasons this happen. For this particular case, it died and will not allow a localhost root access, even with password. If you encounter similar problems and have no idea how to fix it, this is how I fixed mine (Ubuntu 14.04.1 LTS).

Step 1: SSH into your server.
1
Step 2: Enter initctl --system stop mysql to Stop current MySQL process
Step 3: Enter sudo mysqld --skip-grant-tables to start MySQL without grant mode. It will not not return to a command prompt after running so…

Step 4: Open a new SSH client and log in again.
2
Step 5: Enter mysql -u root mysql
Step 6: At mysql> prompt Enter UPDATE user SET Password=PASSWORD('your_new_root_password') where USER='root';
Step 7: Still at mysql> prompt Enter FLUSH PRIVILEGES;
Step 8: Still at mysql> prompt Enter Exit

Step 9: Close/Disconnect the first SSH.
3
Step 10: Enter /etc/init.d/mysql restart to restart MySQL
Step 11: Enter mysql -u root -p followed by your_new_root_password to test localhost root access.

If it shows welcome to the mysql monitor that means you have successfully fixed your crapped out MySQL.

 

Congratulations!

PS: I just remember I can use screen/byobu instead of connecting multiple SSH client, but I was rushing for time, so in the war of style vs substance, form vs function, elegant aesthetic vs raw content, I say screw elegance/style/form. Form follows function anyways heh