Set mysql’s root password to null
When I’m working on a local machine, I usually use mysql’s root password as nothing. Recently, I changed to a different laptop which had the root password setted (and I didn’t know which one was it, by the way!). This recipe explains how we can make the password be set to null
This recipe consists on the following steps, according to this post in stackoverflow, which I put in my blog for future reference. All credits go to the author in the referenced site.
If we want an empty password, then we cannot use the Password hash function. Therefore, first, on the command line, we have to:
sudo service mysql stop sudo mysqld_safe --skip-grant-tables --skip-networking mysql -uroot
And after that, in MySQL:
use mysql; update user set password=null where User='root'; flush privileges; quit;
This mechanism makes it possible to start MySQL without security checks, which allows us to log in with root user without password. Adter that, we change the root password to null, we flush privileges and we are ready to go. From that point on, everytime MySQL starts, root will have no password.