So you have chosen an awesome cryptic password that not even you can remember! It happens to us all, but fear not, it’s quite a simple job to reset this. Not sure if we should be worried over how easy it is to reset the root password for your mysql server, but we wont complaint for the moment.
So first thing you need to do to be able to do this is have root shell access to your server. The following commands are specific to Red Hat/Centos, but the same process can be used for any linux distro if you update the command accordingly.
Once you are connected to your server you must disable mysql.
service mysqld stop
Now that it is stopped you can enter the following command
mysqld --skip-grant-tables --user=root
You should now have access to update the internal tables for SQL. Now you can log into mysql and reset the password. The semi colon at the end of the line is important! Otherwise the command will keep going with an arrow. I.e ‘->’
mysql -u root UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES; quit
Now you should be able to start the server back up.
service start mysqld