How to change user password on MySQL

Today let’s talk about how to change MySQL user password

We can use 2 ways to change the password, 1 – mysqladmin, 2 – linguagem SQL

This is a step by step video of this post:

1. mysqladmin:

In order to change the password using mysqladmin, the syntax is easy:

 mysqladmin -u USER -p password NEWPASSWORD

Let’s then change the password of ‘marcelo’ user to ‘123’

mysqladmin -u marcelo -p password '123'

For this command, we have 3 problems:

. You can just change your own user

. You need SUPER PRIVILEGES to run this command

. If you share you linux user account with other users, this command will appear on historic, to avoid it we can edit ~/.bash_history and delete this lines

2. SQL (the best on my opinion):

To change the password, we’ll just run an update on user’s table on mysql db, you can do this in 2 ways, both have the same result

SET PASSWORD FOR 'user'@'host' = PASSWORD('newpass');


UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='user' AND Host='host';

After run the above command, we need to FLUSH PRIVILEGES to tell mysql to reload the user table

Let’s change the password of ‘marcelo’ user to ‘123’

UPDATE mysql.user SET Password=PASSWORD('123') WHERE User='marcelo' AND Host='localhost';


If you are using mysql command line, you also will have the same problem as mysqladmin, the historic , to hide it, we can edit the file on ~/.mysql_history

Is this, I hope you enjoy!
Any question, just leave a comment

8 thoughts on “How to change user password on MySQL

  1. after changed password with command…
    SET PASSWORD FOR ‘user’@’host’ = PASSWORD(‘newpass’);
    UPDATE mysql.user SET Password=PASSWORD(‘newpass’) WHERE User=’user’ AND Host=’host’;

    1. Hi Karan Solanki,
      you need to configure phpmyadmin to use the password you set on the steps above. If you look the error message, it’s saying that you are trying to access with user root without password – (using password: NO)

Leave a Reply

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