The right way
I've seen many guides that state to reset the MySQL root password you must start the daemon with the
--skip-grant-tables option so you can login without credentials, make the changes and then restart the daemon again.
The problem with this is
- You have to stop and then start the service with no credentials needed ( much security risk many hack wow!! )
- You then also have to stop and start the service again
With this way you wont need to start the service with an insecure config and then restart it again, this way only requires one restart!!
Create a file eg:
/var/lib/mysql/mysql.init with the contents
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('mynewpassword');
And add this line to
[mysqld] block. Restart the mysql service
service mysqld restart
And login as root with your new creds!
mysql -u root -p
You can then delete the file and line you added to
BAM one restart such secure!