Mysql – New and old passwords on same MySQL database

MySQLmysql-5.5password

Is it possible to set up a user in MySQL 5.5 with a new password whilst keeping existing users with the old type of passwords? By old and new passwords I mean the style of hash.

I was thinking I could try specify the hash directly but I'm struggling to get that working (I'm new MySQL).

Unfortunately I can't update all users to the new type of passwords as it would break access to a system I can't control. I also need the default new account to use the old style hash.

Best Answer

It is possible before version 5.7, where it has been disabled.

To set up an old password for a user, use command:

SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('mypass');

More information: Password Hashing in MySQL.

You can enable/disable old passwords globally or per session. On a server where they are enabled globally (i.e. the server was started with old_passwords = 1), run this:

SET @@session.old_passwords = 0;
SET PASSWORD FOR 'test'@'localhost' = PASSWORD('mypass');

to disable them for a session. The PASSWORD in the above snippet will return a password in the new format, affecting only the current session.