Submitted by: Sridhar MS(sridhar.ms@gmail.com)

Tuesday Jan 21st 2020 by Sridhar MS

Language: SQL, Expertise: Intermediate: See how to easily encrypt text in MySQL with the compress method.

There are instances in which we would like to encrypt some text and store it for future reference. It could be some passwords or any other kind of information that may need to be kept secret.

Consider the following query. We are attempting to store the text 'MyName' as encrypted. Of course, we aren't using any encryption mechanisms here, however, we are using the COMPRESS method that comes in handy.



This results as below.

| COMPRESS('MyName')                |
| \0\0\0x???K?M\0?H   | 

We can retrieve the text using UNCOMPRESS over the COMPRESS method.

Mobile Site | Full Site