How to change mysql password?

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To set up a root password for the first time, use the mysqladmin command at the shell prompt as follows:

$ mysqladmin -u root password ‘newpassword’

If you want to changeĀ a root password, then you need to use the following command:

$ mysqladmin -u root -p ‘oldpassword’ password ‘newpassword’

MySQL stores usernames and passwords in the user table inside the MySQL database. You can directly update a password using the following method to update or change passwords:

1) Login to the MySQL server, type the following command at the shell prompt:

$ mysql -u root -p

2) Use the mysql database (type commands at the mysql> prompt):

mysql> use mysql;

3) Change password for a user:

mysql> update user set password=PASSWORD(“newpassword”) where User=’root’;

mysql> flush privileges;
mysql> quit

Leave a Reply

Your email address will not be published. Required fields are marked *


*