How to use the MySQL CRC32() function
The CRC32()
function in MySQL calculates the cyclic redundancy check value of a string. It can be used to generate a checksum value for data validation purposes.
The CRC32()
function in MySQL calculates the cyclic redundancy check value of a string. It can be used to generate a checksum value for data validation purposes.
Syntax
The syntax for CRC32()
is:
CRC32(string)
Where string
is the input string to calculate CRC32 checksum for.
Examples
-
Get CRC32 checksum of a string:
SELECT CRC32('MySQL Tutorial');
This returns a checksum value of 3259397556.
-
Calculate CRC32 for a numeric string:
SELECT CRC32('2534638');
This returns 3888210770.
-
Get CRC32 checksum for a string with spaces:
SELECT CRC32('CRC32 Examples');
This returns 966258668.
-
Calculate CRC32 checksum for a longer string:
SELECT CRC32('This is an example string to demonstrate CRC32');
This returns 1093078499.
-
Generate CRC32 checksum from concatenating strings:
SELECT CRC32(CONCAT('Hello ', 'World'));
This returns 2338997927.
Other Similar Functions
Other checksum functions in MySQL:
MD5()
- Calculate MD5 checksumSHA1()
- Calculate SHA1 checksumSHA2()
- Calculate SHA2 checksumCHECKSUM()
- Calculate live checksum
So CRC32()
provides a way to easily generate a cyclic redundancy checksum for data validation in MySQL.