Changing the root password on MySQL

Last Updated: May 5th, 2017 - Paul Anderson

Many distributions of Linux have an option to install MySQL. In this case, or even if you compile MySQL, the default password is blank. MySQL can also run on Windows boxes. When you install MySQL, make sure that you set the root password. You can do this:

root@u-1:/home/u-1# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 3.23.47
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> SET PASSWORD FOR root@localhost=PASSWORD('rubberchicken');
Query OK, 0 rows affected (0.06 sec)
mysql>

In this example, we set the root password to rubberchicken. Note from the above that the password wasn’t set. If we try this again, we need to use the -p option to enter the password: