Encryption and Compression Functions
954
•
COMPRESS(string_to_compress)
[954]
Compresses a string and returns the result as a binary string. This function requires MySQL to have
been compiled with a compression library such as
zlib
. Otherwise, the return value is always
NULL
.
The compressed string can be uncompressed with
UNCOMPRESS()
[957]
.
mysql>
SELECT LENGTH(COMPRESS(REPEAT('a',1000)));
-> 21
mysql>
SELECT LENGTH(COMPRESS(''));
-> 0
mysql>
SELECT LENGTH(COMPRESS('a'));
-> 13
mysql>
SELECT LENGTH(COMPRESS(REPEAT('a',16)));
-> 15
The compressed string contents are stored the following way:
• Empty strings are stored as empty strings.
• Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first),
followed by the compressed string. If the string ends with space, an extra “
.
” character is added
to avoid problems with endspace trimming should the result be stored in a
CHAR
or
VARCHAR
column. (However, use of nonbinary string data types such as
CHAR
or
VARCHAR
to store
compressed strings is not recommended anyway because character set conversion may occur.
Use a
VARBINARY
or
BLOB
binary string column instead.)
•
DECODE(crypt_str,pass_str)
[954]
Decrypts the encrypted string
crypt_str
using
pass_str
as the password.
crypt_str
should be
a string returned from
ENCODE()
[955]
.
•
DES_DECRYPT(crypt_str[,key_str])
[954]
Decrypts a string encrypted with
DES_ENCRYPT()
[954]
. If an error occurs, this function returns
NULL
.
This function works only if MySQL has been configured with SSL support. See
Section 6.3.6, “Using
SSL for Secure Connections”
.
If no
key_str
argument is given,
DES_DECRYPT()
[954]
examines the first byte of the encrypted
string to determine the DES key number that was used to encrypt the original string, and then reads
the key from the DES key file to decrypt the message. For this to work, the user must have the
SUPER
[578]
privilege. The key file can be specified with the
--des-key-file
[407]
server option.
If you pass this function a
key_str
argument, that string is used as the key for decrypting the
message.
If the
crypt_str
argument does not appear to be an encrypted string, MySQL returns the given
crypt_str
.
•
DES_ENCRYPT(str[,{key_num|key_str}])
[954]
Encrypts the string with the given key using the Triple-DES algorithm.
This function works only if MySQL has been configured with SSL support. See
Section 6.3.6, “Using
SSL for Secure Connections”
.
The encryption key to use is chosen based on the second argument to
DES_ENCRYPT()
[954]
,
if one was given. With no argument, the first key from the DES key file is used. With a
key_num
argument, the given key number (0 to 9) from the DES key file is used. With a
key_str
argument,
the given key string is used to encrypt
str
.
The key file can be specified with the
--des-key-file
[407]
server option.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...