Say I have a password "Foobar1234". In MySQL database (5.6), the hash value is


I want to try this outside of MySQL database so the SQL query isn't logged. Is the hash function known? I am using the default settings.

Here is the doc: https://dev.mysql.com/doc/refman/5.6/en/password-hashing.html


1 Answer 1


This question was explained several times in the DBA StackExchange

I actually learned the formula from a post from PalominoDB (later changed name to Blackbird and then was purchased by Pythian). The post was made Dec 4, 2011 entitled "Hashing Algorithm In MySQL PASSWORD()"

So if you want to execute this function yourself, it would look something like this:

SET @my_new_pass = 'WhateverIWantAsThePassword';
SET @my_new_hash = CONCAT('*',UPPER(SHA1(UNHEX(SHA1(@my_new_pass))))) MySQLPWDHASH;

This would land in the MySQL history ~/.mysql_history but not in the binary logs.

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