w3resource

MySQL ENCODE() function

ENCODE() function

MySQL ENCODE() function encrypts a string. This function returns a binary string of the same length of the original string.

Syntax:

ENCODE(str, pass_str);

Arguments:

Name Description
str A string which is to be encrypted.
pass_str A string to encrypt str.

Syntax Diagram:

MySQL ENCODE() Function - Syntax Diagram

MySQL Version: 8.0


Example:

Code:

SELECT ENCODE('mytext','mykeystring');

Explanation:

The above MySQL statement will encrypt the string 'mytext' with 'mykeystring'.

Output:

mysql> SELECT ENCODE('mytext','mykeystring');
+--------------------------------+
| ENCODE('mytext','mykeystring') |
+--------------------------------+
| ">¿¡È                         | 
+--------------------------------+
1 row in set (0.00 sec)

Example: MySQL encode() function using table

Sample table: testtable


Code:

INSERT INTO testtable VALUE(ENCODE('myencodetext','mypassw'));

Explanation:

The above MySQL statement inserts encrypted data into table 'testtable'.

Output:

mysql> INSERT INTO testtable VALUE(ENCODE('myencodetext','mypassw'));
Query OK, 1 row affected (0.00 sec)

Previous: DES_ENCRYPT()
Next: ENCRYPT()



Follow us on Facebook and Twitter for latest update.