MySQL Tips: Howto change the MySQL root password
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:
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
Method 2: using mysqladmin
mysqladmin -u root password "newpass"
if there was already a mysql root password set, change this to:
mysqladmin -u root password oldpass "newpass"
Method 3: using UPDATE to directly edit the users table
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
>
Tags: mysql
1st February 2008, 08:29
Sure, this works, but only when you remenber current mysql root password. Otherwise you have to restart mysqld like
)
#mysqld –skip-grant-tables –user=root
and use the 3-rd method you’ve mentioned.
Trust me, I had to use this way numerous times (especially on RHEL after installing MySQL using yum
1st February 2008, 20:46
Ehh… That was meant for a future post, on how to retrieve a lost mysql password
5th February 2008, 12:55
Oops, sorry
21st June 2008, 21:30
This was on target and exactly what I was looking for. I hit several dozen sites and more help files than I can recall, and they were ALL about resetting a lost password. Great to know, but not what I was looking for. This was very helpful. Thank you.