Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to keep sensitive data such as user's e-mail address in MySQL database in encrypted form.

  1. Is it possible to encrypt/decrypt mail column in MySQL using ssh-key forwarded by ssh-agent on the fly while using mysql monitor or performing SQL queries? I have never seen such plugin or patch so I guess not but it is worth asking.

  2. How can I use ssh-agent inside the script (perl/bash) to decrypt column value which has been encrypted with my public ssh key?

I would appreciate any hints.

By the way that would be a great idea to have a MySQL function to do so:

SELECT user, SSH_DECRYPT(mail) FROM users;

and SSH_DECRYPT uses ssh-agent defined somewhere, for example in /etc/mysql/my.cnf. Or even better:

SELECT user, SSH_DECRYPT(mail, '/var/run/ssh-agent/users-key.sock');
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.