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:

  • plain_string – It is used to specify the plain text that is to be encoded.
  • password_string – It is used to specify the password string to encode the plain text string.

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



Supported Versions of MySQL:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1

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 
My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.