Turning on encryption is only half the job of securing a MySQL database. This guide shows how to protect data in transit with TLS, protect stored data with TDE, and keep your encryption keys safe. It also covers how to encrypt logs and backups, and how to avoid the common gaps teams miss.
Abish November 11, 2026
Encrypting a MySQL database is not just a configuration change. It is a chain of controls covering data in transit, data at rest, backups, and the keys that protect them. This guide walks through each layer for MySQL 8.x, highlights the gaps teams commonly miss, and shows how to build the evidence an auditor expects.
MySQL encryption protects database information by converting it into unreadable form using secret keys. It covers three areas: data in transit (protected by TLS), data at rest (protected by Transparent Data Encryption, or TDE), and the keys, logs and backups that support them. If the data is intercepted or stolen, it stays unreadable without the key.
Get expert support for MySQL security and encryption.
Explore MySQL Security Services →Before touching any configuration, write down what you are protecting and from whom. Encryption controls only make sense when mapped to a threat.
| Data location | Typical threat | Control |
|---|---|---|
| Client to server, replication links | Sniffing, man-in-the-middle | TLS 1.2 / 1.3 |
| Tablespaces, redo/undo, temp files | Stolen disk or VM snapshot | Transparent Data Encryption (TDE) |
| Binary and relay logs | Log theft (they contain full row data) | Binlog encryption |
| Backups and dumps | Backup media theft | Encrypted backups |
| Highly sensitive columns (card numbers, national IDs) | DBA or application-level exposure | Application or column encryption |
| Keys | Everything above | Key management and rotation |
It scrambles data as it travels between the app and the database, so anyone listening on the network sees only gibberish. Turning it on is not enough; you must also require it, or insecure connections can still slip through.
[mysqld]
ssl_ca=/etc/mysql/certs/ca.pem
ssl_cert=/etc/mysql/certs/server-cert.pem
ssl_key=/etc/mysql/certs/server-key.pem
tls_version=TLSv1.2,TLSv1.3
require_secure_transport=ON
Turning TLS on only allows encrypted connections. Plaintext clients still connect unless you enforce it. require_secure_transport=ON enforces it globally.
Replication traffic carries your data too. On the replica:
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='db-primary.example.internal',
SOURCE_SSL=1,
SOURCE_SSL_CA='/etc/mysql/certs/ca.pem',
SOURCE_SSL_CERT='/etc/mysql/certs/client-cert.pem',
SOURCE_SSL_KEY='/etc/mysql/certs/client-key.pem';
On older MySQL versions and on MariaDB, use CHANGE MASTER TO ... MASTER_SSL=1 with the matching MASTER_SSL_* options.
SHOW GLOBAL VARIABLES LIKE 'tls_version';
SHOW GLOBAL VARIABLES LIKE 'require_secure_transport';
SHOW SESSION STATUS LIKE 'Ssl_cipher';
To find plaintext connections across the server (MySQL):
SELECT t.PROCESSLIST_USER AS user,
t.PROCESSLIST_HOST AS host,
s.VARIABLE_VALUE AS cipher
FROM performance_schema.threads t
JOIN performance_schema.status_by_thread s USING (THREAD_ID)
WHERE s.VARIABLE_NAME = 'Ssl_cipher'
AND t.TYPE = 'FOREGROUND';
The empty cipher on legacy_job means a plaintext connection. That is exactly the finding you want to discover before the auditor does.
This scrambles data stored on disk, so a stolen hard drive or snapshot is unreadable. The database locks and unlocks the data automatically, so applications keep working unchanged.
TDE needs a place to keep the master key. Prefer the component-based keyring (component_keyring_file, component_keyring_encrypted_file, or the Enterprise and Percona options for Vault, KMIP and cloud KMS). The older keyring plugins are deprecated.
A plain file keyring on the same disk as the data is fine for a lab, but it is hard to defend in an audit: whoever steals the disk steals the key as well. For production, use Vault or a cloud KMS.
[mysqld]
default_table_encryption=ON
table_encryption_privilege_check=ON
innodb_redo_log_encrypt=ON
innodb_undo_log_encrypt=ON
innodb_temp_tablespaces_encrypt=ON
binlog_encryption=ON
Note that binlog_encryption=ON also encrypts relay logs on replicas.
default_table_encryption only affects new tables. Existing ones stay plaintext until you convert them:
-- A single table (this rebuilds it)
ALTER TABLE sales.orders ENCRYPTION='Y';
MariaDB uses plugins and encrypts in the background with worker threads, so there is no big-bang rebuild:
[mysqld]
plugin_load_add=file_key_management # or hashicorp_key_management
file_key_management_filename=/secure/keys.enc
file_key_management_encryption_algorithm=AES_CBC
innodb_encrypt_tables=ON # or FORCE
innodb_encrypt_log=ON
innodb_encryption_threads=4
innodb_encryption_rotate_key_age=1
encrypt_binlog=ON
aria_encrypt_tables=ON
encrypt_tmp_disk_tables=ON
encrypt_tmp_files=ON
Track progress with information_schema.INNODB_TABLESPACES_ENCRYPTION. As with MySQL, keep the key file itself encrypted and off the data volume; Hashicorp Vault or a KMS is the better production choice.
The keyring holds the secret keys that lock the data. Keeping it on the same disk as the data is like taping a safe’s key to the safe, so use a separate vault or key service. Encryption is only as strong as the handling of its keys.
An encrypted database with an unencrypted backup is an unencrypted database.
# Logical backup, encrypted with GPG
mysqldump --single-transaction --routines sales | gzip | gpg --encrypt --recipient backup-key@example.com > sales_$(date +%F).sql.gz.gpg
# Logical backup, encrypted with OpenSSL
mysqldump --single-transaction sales | openssl enc -aes-256-cbc -pbkdf2 -salt -pass file:/secure/backup.pass > sales_$(date +%F).sql.enc
For physical backups, use xtrabackup or mariabackup with their encryption options. Add storage-layer encryption too (for example S3 SSE-KMS), keep keys separate from the backup location, and schedule restore tests. A restore test that succeeds with the retrieved key is audit evidence.
For restore testing and recovery planning, see our MySQL backup and recovery services.
Explore Backup Services →
Because TDE is transparent, anyone with SELECT sees plaintext. For regulated fields such as card numbers or national IDs, add another layer:
Even teams that "enabled encryption" often leave these exposed:
Get expert help with database security, encryption, and audit readiness.
Talk to Mafiree →Miru IT Park, Vallankumaranvillai,
Nagercoil, Tamilnadu - 629 002.
Unit 303, Vanguard Rise,
5th Main, Konena Agrahara,
Old Airport Road, Bangalore - 560 017.
Call: +91 6383016411
Email: sales@mafiree.com