How to change user password on MySQL

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

We can use 2 ways, 1 – mysqladmin, 2 – linguagem SQL

This is a step by step video of this post:

1. 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

Liked? Help and Share!
This entry was posted in MySQL, password. Bookmark the permalink.
  • Edmar Roberto Prandini

    Eu posso usar esse comando SQL no PHPMyAdmin?

    • marceloaltmann

      A opcao 2 tu pode usar sim. Abs

  • PJ Brunet

    Note, option #1 will prompt for the old password.

  • thanks for solution…

  • Gpzim Pacheco

    Thanks. Excelent solution.

  • karan solanki

    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’;

    • Marcelo Altmann

      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)

    • Star catch

      open and then find and add your password. It gives you that error for you have change your password