Tablespaces and Encryption

Tablespaces, Compression, and Table Encryption

Each table normally has its own file, /var/lib/mysql/shop/orders.ibd. A general tablespace (CREATE TABLESPACE shop_archive ADD DATAFILE 'shop_archive.ibd', then ALTER TABLE orders_2025 TABLESPACE shop_archive) holds several tables and belongs to the server: it survived DROP DATABASE in testing.

ROW_FORMAT=COMPRESSED squeezes 16 KB pages into KEY_BLOCK_SIZE KB; COMPRESSION='zlib' or 'lz4' compresses pages on write and punches holes in the file. The innodb_file_format setting in old guides was removed in MySQL 8.0 524 .

300,000 log lines uncompressed, page-compressed and row-compressedSQL
CREATE TABLE log_plain (id INT AUTO_INCREMENT PRIMARY KEY, msg TEXT NOT NULL);
CREATE TABLE log_page LIKE log_plain;  ALTER TABLE log_page COMPRESSION = 'zlib';
CREATE TABLE log_row LIKE log_plain;
ALTER TABLE log_row ROW_FORMAT = COMPRESSED KEY_BLOCK_SIZE = 8;
INSERT INTO log_plain (msg)
  SELECT CONCAT('GET /books/', id, ' 200 ', REPEAT('Mozilla/5.0 (X11; Linux x86_64) ', 4))
    FROM order_events LIMIT 300000;
INSERT INTO log_page (msg) SELECT msg FROM log_plain;
INSERT INTO log_row (msg) SELECT msg FROM log_plain;
SELECT NAME, FILE_SIZE, ALLOCATED_SIZE FROM information_schema.INNODB_TABLESPACES
 WHERE NAME LIKE 'shop/log%';
Output
+----------------+-----------+----------------+
| NAME           | FILE_SIZE | ALLOCATED_SIZE |
+----------------+-----------+----------------+
| shop/log_plain |  67108864 |       67112960 |
| shop/log_page  |  67108864 |       24535040 |
| shop/log_row   |  31457280 |       31461376 |
+----------------+-----------+----------------+

Page compression allocated 23 MB behind an apparent 64 MB, which ls -l still reports; row compression made a real 30 MB file. Both cost CPU on writes.

ENCRYPTION='Y' encrypts a tablespace at rest, and without a keyring fails with error 3185, Can't find master key from keyring. The keyring_file plugin was removed in MySQL 8.4; load component_keyring_file instead, through a mysqld.my manifest beside mysqld containing {"components": "file://component_keyring_file"} and a component_keyring_file.cnf in the plugin directory giving path and read_only. In a mysql:9.7 test container the first start left an empty key file and the component Disabled; deleting the file and running ALTER INSTANCE RELOAD KEYRING fixed it. grep then found a test token in a plain table's .ibd file but not in the encrypted one. Back up the keyring, or the encrypted tables are lost with it.