Encryption and compression MySQL functions Stay organized with collections Save and categorize content based on your preferences.
Spanner supports the following MySQL encryption and compressionfunctions. You need to implement the MySQL functions in yourSpanner database before you can use them. For more information oninstalling the functions, seeInstall MySQL functions.
Function list
| Name | Summary |
|---|---|
mysql.SHA2 | Calculates a SHA-2 checksum. |
mysql.SHA2
mysql.SHA2(bytes_expression,hash_length)Description
Calculates an SHA-2 checksum for the inputBYTES.
This function supports the following arguments:
bytes_expression: TheBYTESvalue for which to calculate the checksum.hash_length: The chosen bit length of the hash. Supported values are 256and 512.
Return data type
STRING
Differences from MySQL
The MySQL version ofSHA2() also supports SHA-224 and SHA-384 hash lengths,which this function does not. Additionally, this function returns the checksum as ahexadecimalSTRING, while the MySQL version returns binary data.
Limitations
This function only supports hash lengths of 256 and 512 bits. The output isalways a hexadecimal string, not binary data. If you provide an unsupportedhash_length, the function returns an error.
Example
The following example calculates the SHA-256 checksum for aBYTES value:
SELECTmysql.SHA2(B'GoogleCloud',256)assha256_checksum;/*+------------------------------------------------------------------+| sha256_checksum |+------------------------------------------------------------------+| 2002A3F1F350598F5FAF799AD9C9936908230796712E24682016E5257A4D2000 |+------------------------------------------------------------------+*/Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.