MDLog:/sysadmin

The Journal Of A Linux Sysadmin

MySQL Tips: Howto Change the MySQL Root Password

| Comments

Here is a quick tip that will show several methods to change the mysql root password (that is normally empty at mysql initial install).

Method 1: using the SET PASSWORD command:

1
2
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Method 2: using mysqladmin

1
mysqladmin -u root password "newpass"

if there was already a mysql root password set, change this to:

1
mysqladmin -u root password oldpass "newpass"

Method 3: using UPDATE to directly edit the users table

1
2
3
4
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE User = 'root';
mysql> FLUSH PRIVILEGES;

Comments