Open In App

MySQL | ENCODE( ) Function

Last Updated : 13 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads