A compliance auditor asks “is the database encrypted at rest?” and the honest answer is more nuanced than the question. Full-disk encryption (LUKS) covers the case of a stolen drive but not a leaked tablespace file copied off a running host. InnoDB transparent data encryption (TDE) covers tablespaces, redo logs, and undo logs at the engine level — and it lives or dies on key management. This article is the procedure we follow when standing up MySQL 8 TDE for a client and the operational shape of running it after day one.
How to verify
Before enabling TDE, confirm the build supports it and check what is already encrypted.
mysql -e "SHOW PLUGINS;" | grep -i keyring
mysql -e "SELECT @@keyring_file_data, @@innodb_redo_log_encrypt, @@innodb_undo_log_encrypt;"
mysql -e "SELECT NAME, ENCRYPTION FROM information_schema.innodb_tablespaces LIMIT 20;"
mysql -e "SELECT TABLE_SCHEMA, TABLE_NAME, CREATE_OPTIONS FROM information_schema.tables WHERE CREATE_OPTIONS LIKE '%ENCRYPTION%';"
ls -la /var/lib/mysql-keyring/
SHOW PLUGINS should list one of keyring_file, keyring_okv, keyring_aws, or component_keyring_* as active. If no keyring is loaded, no tablespace can be encrypted.
What’s happening
InnoDB TDE uses a two-tier key hierarchy. Every encrypted tablespace has its own tablespace key, stored in the tablespace header and encrypted with a master key kept in the keyring. When you rotate the master key, MySQL re-encrypts only the tablespace key headers — fast, milliseconds — not the entire dataset. The actual table data is encrypted with the tablespace key, which never leaves the file.
The keyring is the trust root. keyring_file writes the master key to a local file (acceptable for non-regulated workloads, weaker than HSM-backed options). component_keyring_kmip talks to a KMIP-compliant key manager. keyring_aws integrates with AWS KMS. The plugin choice drives the operational model: file-based keyrings need their own backup discipline; HSM-backed keyrings transfer the trust boundary but require network availability to the key service for MySQL to start.
What TDE does NOT protect: data in memory (the buffer pool holds decrypted pages), data in transit (use TLS), data in mysqldump output (use --default-character-set=utf8mb4 plus an out-of-band re-encryption), backup files unless the backup tool understands the encryption, and the binlog by default (use binlog_encryption=ON).
The procedure
-
Install and load a keyring component. On MySQL 8.0.24+, components are preferred over the older plugin interface. The simplest production starting point is
component_keyring_filewith the keyring file on a dedicated mount, ownedmysql:mysql, mode 0600.sudo mkdir -p /var/lib/mysql-keyring sudo chown mysql:mysql /var/lib/mysql-keyring sudo chmod 750 /var/lib/mysql-keyringWrite
/var/lib/mysql/component_keyring_file.cnf:{ "path": "/var/lib/mysql-keyring/component_keyring_file", "read_only": false }Register the component in
mysqld --initialize-insecureruns viamysqld.my, or for an existing instance:INSTALL COMPONENT 'file://component_keyring_file'; -
Enable encryption defaults in
/etc/mysql/mysql.conf.d/encryption.cnf:[mysqld] default_table_encryption = ON table_encryption_privilege_check = ON innodb_redo_log_encrypt = ON innodb_undo_log_encrypt = ON binlog_encryption = ONRestart MySQL. New tables created without an explicit
ENCRYPTIONclause will inherit the schema default; schemas inherit the global default. -
Encrypt existing tables. This is an online operation but is rewriting the tablespace file, so it locks for the duration of the rebuild on older versions. On MySQL 8 the rebuild is online.
ALTER TABLE app.orders ENCRYPTION='Y', ALGORITHM=INPLACE, LOCK=NONE;Run during a maintenance window for very large tables; check disk space (the rebuild creates a shadow tablespace).
-
Rotate the master key. This re-encrypts every tablespace key header with the new master; tablespace keys themselves are untouched, so the operation is fast regardless of dataset size.
ALTER INSTANCE ROTATE INNODB MASTER KEY;Capture the keyring file in your backup right after rotation; the master key has a version number written into the keyring.
-
Back up the keyring on every change. A backup of an encrypted tablespace without the keyring is unrecoverable.
sudo systemctl stop mysql sudo tar -czf /backup/mysql-keyring-$(date +%F).tar.gz \ -C /var/lib/mysql-keyring . sudo systemctl start mysqlOr, less invasively, snapshot the keyring directory on the same cadence as
mysqlbackup/xtrabackupruns. -
Validate restore on a fresh host. Copy the data directory, copy the keyring, start MySQL — if the keyring is missing or unreadable, the server starts but every encrypted tablespace returns errors.
mysql -e "SELECT NAME, ENCRYPTION FROM information_schema.innodb_tablespaces WHERE ENCRYPTION='Y' LIMIT 5;" mysql -e "SELECT COUNT(*) FROM app.orders;"
Common pitfalls
- Keyring not in the backup — the single most common TDE failure in restore drills. The keyring is the encrypted database’s key; lose it, lose the data.
binlog_encryption=OFF— the binlog contains row-level change data in cleartext on disk. Replicas reading from cleartext binlogs make the encryption-at-rest claim untrue.- No master key rotation policy — compliance frameworks expect rotation on schedule (90 or 180 days is typical). Document the rotation cadence and verify it actually runs.
keyring_fileon the same disk as the tablespace files — defeats the threat model. The keyring belongs on a separate mount, ideally with separate access controls.- Re-encrypting an active table without a maintenance window — even online
ALTERconsumes I/O and disk space; for a multi-terabyte table this is a planned event, not a sudden one.
TDE is a control that costs almost nothing in steady-state CPU but everything in operational discipline — the day you lose the keyring is the day the encrypted database becomes a brick. In the engagements we run, the keyring backup is on a separate schedule from the data backup, restore drills explicitly cover the encrypted-tablespace path, and master-key rotation is on the same cadence as the rest of the secrets we manage. For the broader pattern of operating MySQL with compliance constraints, see /en/services/managed-operations/.