Setting MySQL root password to nothing


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

How to

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;


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.


One comment

  1. I tested this recipe on OS X with mysql 5.7.13:

    $mysql –version
    mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using EditLine wrapper

    Step 3 in mysql should be:

    mysql> update user set authentication_string=null where User=’root’;

    I’m not sure if this difference is related to the operating system or MySQL.

    However, great recipe. 😉


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s