Open In App

MySQL | ENCODE( ) Function

The MySQL ENCODE() function is used for encoding a plain text string. The MySQL ENCODE() function returns a binary string which of the same size of the plain text string. The MySQL DECODE() function returns empty strings if the string passed is an empty string.

The ENCODE() function accepts two parameters which are the string to be encoded and the key string to encode the plain text string.



Syntax:

ENCODE(plain_string, password_string);

Parameters Used:



Return Value:
The ENCODE function in MySQL returns a binary string after encoding.

Supported Versions of MySQL:

Example-1: Implementing ENCODE function on a string.

SELECT  
ENCODE('geeksforgeeks', 'passwordstring'); 

Output:

Q)?P????j[K 

Example-2: Implementing ENCODE function on a string which has a combination of characters and integers.

SELECT  
ENCODE('geeksforgeeks123', 'passwordstring'); 

Output:

Q)?P????j[K??= 

Example-3: Implementing ENCODE function on a NULL string.

SELECT  
ENCODE('NULL', 'passwordstring'); 

Output:

NULL 
Article Tags :
SQL