How To Change The Root Password In MySQL

Using mysqladmin on the command line
If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root.
1 2 |
$ mysql -u root mysql> |
To set the root password for the first time, use mysqladmin
:
1 |
$ mysqladmin -u root password 'NewPasswordHere' |
However, if you want to change (or update) a root password, then you need to use the following command:
1 |
$ mysqladmin -u root -p'oldpassword' password 'NewPasswordHere' |
For example, to change the password from foo to bar:
1 |
$ mysqladmin -u root -p'foo' password 'bar' |
Using SQL commands at the mysql prompt
1 2 3 4 5 |
$ mysql -u root -p mysql> use mysql; mysql> update user set password=PASSWORD("NewPasswordHere") where User='eric'; mysql> flush privileges; mysql> quit |
Leave Your Comment
All fields marked with "*" are required.