This tutorial explains how to use the MySQL ENCRYPT function with syntax and examples.
The MySQL ENCRYPT function is used to encrypt a string using UNIX crypt().
The syntax for the ENCRYPT function in MySQL is:
ENCRYPT( string [, salt ] )
The plaintext string that is encrypted using UNIX crypt().
Optional. The string that is at least 2 characters long that is used in the encryption process. If salt is not provided, the ENCRYPT function will use a random value.
The ENCRYPT function can be used in the following versions of MySQL:
Let's look at some MySQL ENCRYPT function examples and explore how to use the ENCRYPT function in MySQL.
For example:
mysql> SELECT ENCRYPT('abc');
Output: 'HodO.ryHDWKR2'
mysql> SELECT ENCRYPT('password');
Output: 'Xp7fKf8gFYoMc'
mysql> SELECT ENCRYPT('AODBA');
Output: 'ipQqyRshr94pU'
mysql> SELECT ENCRYPT('AODBA', '123');
Output: '120RNc3daWyrU'
mysql> SELECT ENCRYPT('AODBA', '1');
Output: NULL
mysql> SELECT ENCRYPT(NULL);
Output: NULL