SQL Tutorial SQL Advanced SQL Database SQL References

MySQL SHA() Function



The MySQL SHA() function returns an SHA-1 160-bit checksum representation of a given string. This function returns a 40 character hex string as the result. The result from this function can be used as a hash key.

The SHA() function returns NULL if the string is NULL.

The SHA() is a synonym for the SHA1() function.

Syntax

SHA(string)

Parameters

string Required. Specify the plaintext string used to generate the SHA-1 160-bit checksum.

Return Value

Returns the SHA-1 160-bit checksum representation of a string.

Example:

The example below shows the usage of SHA() function.

mysql> SELECT SHA('xyz');
Result: '66b27417d37e024c46526c2f6d358a754fc552f3'

mysql> SELECT SHA('password');
Result: '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'

mysql> SELECT SHA('alphacodingskills');
Result: '910c3491e62f9d1892600290990b1690a08eb045'

mysql> SELECT SHA(123);
Result: '40bd001563085fc35165329ea1ff5c5ecbdbbeef'

mysql> SELECT SHA(NULL);
Result: NULL

❮ MySQL Functions