I changed my password from old hash to a new hash using the following query

SET SESSION old_passwords=FALSE;
SET PASSWORD = PASSWORD('[your password]');

I found this query on https://stackoverflow.com/questions/1892607/mysql-password-hashing-method-old-vs-new. I replaced [your password] to my own password.

Now I can't log into my db again using the password I set. I was wondering is this password change forever or is the session going to expire and how long till it does.

  • 1
    Did you run FLUSH PRIVILEGES; query to apply privilege changes ?
    – castor
    Apr 25, 2012 at 13:20

1 Answer 1


According to MySQL Documentation on SET PASSWORD

The SET PASSWORD statement assigns a password to an existing MySQL user account. If the password is specified using the PASSWORD() or OLD_PASSWORD() function, the literal text of the password should be given. If the password is specified without using either function, the password should be the already-encrypted password value as returned by PASSWORD().

With no FOR clause, this statement sets the password for the current user. Any client that has connected to the server using a nonanonymous account can change the password for that account

However, you just been struck by lightning because the same webpage says


SET PASSWORD may be recorded in server logs or in a history file such as ~/.mysql_history, which means that plaintext passwords may be read by anyone having read access to that information. See Section 6.1.2, “Password Security in MySQL”.


If you are connecting to a MySQL 4.1 or later server using a pre-4.1 client program, do not use the preceding SET PASSWORD or UPDATE statement without reading Section, “Password Hashing in MySQL”, first. The password format changed in MySQL 4.1, and under certain circumstances it is possible that if you change your password, you might not be able to connect to the server afterward.

Your password change is forever, so to speak.


Suppose your user is myuser@localhost, you can have someone with ALL PRIVILEGES run this

UPDATE mysql.user SET password=OLD_PASSWORD('[your password]')
WHERE user='myuser' AND host='localhost';

If you have no DBA but can restart mysql, then do this

service mysql restart --skip-networking --skip-grant-tables
mysql -e"UPDATE mysql.user SET password=OLD_PASSWORD('[your password]') WHERE user='myuser' AND host='localhost'"
service mysql restart
  • Thanks a lot. Going to ask my system administrator to reset my password Apr 26, 2012 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.