Thesql change password in session

MySQLPHP

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.

Best Answer

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

Important

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

Note

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 6.1.2.3, “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.

HOW TO FIX IT

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';
FLUSH PRIVILEGES;

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
Related Question