Databases 14 min read

Mastering MySQL 5.7 InnoDB Tablespaces: Architecture, Encryption, and Configuration

This article explains the structure and components of MySQL 5.7 InnoDB tablespaces—including system, undo, temporary, and general tablespaces—covers double‑write buffering, redo logs, encryption with keyring, and provides practical configuration examples and command‑line demonstrations.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
Mastering MySQL 5.7 InnoDB Tablespaces: Architecture, Encryption, and Configuration

Background

InnoDB is MySQL's most popular storage engine because it supports ACID, offers good read/write performance, and provides many features essential for database services.

InnoDB System Tablespace

The system tablespace stores table data, InnoDB metadata, MVCC information, and various internal objects such as data pages, index pages, the data dictionary, undo space, double‑write buffer, and insert buffer.

Parameters

Typical settings include InnoDB_data_file_path = /ibdata/ibdata1:10M:autoextend and enabling InnoDB_file_per_table to reduce file fragmentation.

InnoDB Data Dictionary

The data dictionary consists of internal system tables located in the system tablespace that store metadata for tables, indexes, columns, and other InnoDB objects.

Double‑Write Buffer

Before dirty pages are flushed to disk, InnoDB writes them to a contiguous area called the double‑write buffer. If a crash occurs, the buffer provides a complete copy of the data, preventing partial page writes.

Parameter: innodb_doublewrite (enabled by default).

Redo Logs

Redo logs are used for crash recovery. During startup, InnoDB performs auto‑recovery to replay unfinished transactions. They record row changes, old and new column values, session IDs, and timestamps.

Key parameters: InnoDB_log_file_in_group , InnoDB_log_buffer_size , InnoDB_log_file_size .

UNDO Tablespace and Logs

Undo tablespaces contain one or more undo log files that preserve before‑image copies of modified rows to implement MVCC consistency. By default undo logs reside in the system tablespace, but from MySQL 5.6 they can be placed in separate undo tablespaces, which must be configured before server startup and cannot be changed at runtime.

Typical parameters: InnoDB_undo_tablespace , InnoDB_undo_directory , InnoDB_undo_logs , InnoDB_undo_log_truncate .

Key Points

Undo logs in the system tablespace cannot be cleared.

At least two undo tablespaces are required for effective management.

Increasing InnoDB_rollback_segments improves concurrency.

Temporary Tablespace

Before MySQL 5.7, temporary tables shared the system tablespace. Starting with 5.7, they have a dedicated tablespace to reduce I/O impact on normal tables. The temporary tablespace file ibtmp1 is recreated on each server start and is not used for crash recovery.

Parameter: InnoDB_temp_data_file_path = ibtmp1:12M:autoextend (default).

General Tablespace

Introduced in MySQL 5.7.6, a general tablespace can store multiple tables and is created with CREATE TABLESPACE . Tables can be moved between system, file‑per‑table, and general tablespaces using ALTER TABLE … TABLESPACE . It reduces memory usage compared to file‑per‑table storage and supports both Antelope and Barracuda file formats.

Tablespace Encryption (TDE)

MySQL 5.7 supports Transparent Data Encryption (TDE) for InnoDB tables via the keyring_file plugin (or keyring_okv in the Enterprise edition). A master key encrypts per‑tablespace keys, which are stored in the tablespace header. Encryption is enabled with ENCRYPTION='Y' on table creation or alteration.

Key parameters: early-plugin-load , keyring_file_data .

Configuration and Operations

Typical InnoDB configuration for MySQL 5.7 includes:

<code>datadir=/var/lib/mysql
InnoDB_file_per_table=1
InnoDB_buffer_pool_size=2000M
InnoDB_data_file_path=ibdata1:512M;ibdata2:512M:autoextend
InnoDB_log_file_in_group=3
InnoDB_log_file_size=100M
InnoDB_log_buffer_size=30M
InnoDB_file_format=Barracuda
InnoDB_undo_directory=/var/lib/mysql/
InnoDB_undo_tablespaces=3
InnoDB_undo_logs=128
InnoDB_undo_log_truncate=ON
InnoDB_rollback_segments=128
InnoDB_temp_data_file_path=ibtmp1:20M:autoextend
early-plugin-load=keyring_file.so
keyring_file_data=/var/lib/mysql-keyring/keyring
</code>

MySQL Service Initialization Log

Sample notes from the InnoDB startup log show buffer pool initialization, undo tablespace activation, double‑write buffer setup, redo log discovery, and plugin loading.

General Tablespace Example

<code># Create General tablespace
CREATE TABLESPACE gen_tblsp ADD DATAFILE 'gen_tlbsp.ibd' ENGINE=INNODB;
# Verify creation
SELECT * FROM INFORMATION_SCHEMA.FILES WHERE TABLESPACE_NAME='gen_tblsp'\G
# Create a table in the general tablespace
CREATE TABLE gen_ts_tbl (id INT, c_desc VARCHAR(100), c_comments TEXT) TABLESPACE gen_tblsp;
# Insert data
INSERT INTO gen_ts_tbl VALUES (1, 'test', 'General tablespace testing');
# Move an existing table into the general tablespace
CREATE TABLE InnoDB_table (id INT, uname VARCHAR(78));
INSERT INTO InnoDB_table VALUES (1, 'moving to gen_tblsp');
ALTER TABLE InnoDB_table TABLESPACE gen_tblsp;
# Drop tables and tablespace when done
DROP TABLE gen_ts_tbl;
DROP TABLE InnoDB_table;
DROP TABLESPACE gen_tblsp;
</code>
Undo and temporary tablespace diagram
Undo and temporary tablespace diagram
General tablespace illustration
General tablespace illustration

InnoDB TDE with keyring_file Plugin

<code># Verify keyring plugin status
SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'keyring%';
# Show keyring variables
SHOW VARIABLES LIKE '%keyring%';
# Create an encrypted table
CREATE TABLE InnoDB_tde (id INT, c_desc VARCHAR(100), c_comments TEXT) ENCRYPTION='Y';
# Insert data
INSERT INTO InnoDB_tde VALUES (1, 'test tde', 'InnoDB tde testing');
# Disable/enable encryption
ALTER TABLE InnoDB_tde ENCRYPTION='N';
ALTER TABLE InnoDB_tde ENCRYPTION='Y';
# Rotate master key
ALTER INSTANCE ROTATE INNODB MASTER KEY;
</code>

Conclusion

The article provides an overview of MySQL 5.7 InnoDB tablespaces, their types, key parameters, encryption options, and practical command‑line examples to help readers configure and manage InnoDB storage effectively.

InnoDBmysqlencryptionDatabase ConfigurationTablespace
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.