--从mysql 5.7.6 开始其支持 general tablespace,其可以创建在一个相对路径或绝对路径上 --A general tablespace is a shared tablespace, similar to the system tablespace. It can hold multiple tables, --and supports all table row formats. General tablespaces can also be created in a location relative to or independent of the MySQL data directory --创建表空间是必需指定数据文件名(只支持一个数据文件),且以 .db 为后缀 --the data file name must have a .ibd extension. An InnoDB general tablespace only supports a single data file --创建表空间 CREATE TABLESPACE test_ts ADD DATAFILE '/tmp/testts.ibd' ENGINE=INNODB; --FILE_BLOCK_SIZE只在存储压缩表时才必需,注意压缩表和非压缩表不能在同一个表空间中 --The FILE_BLOCK_SIZE setting is only required if you will use the tablespace to store compressed InnoDB tables (ROW_FORMAT=COMPRESSED). --If FILE_BLOCK_SIZE is equal innodb_page_size, the tablespace can only contain tables with an uncompressed row format (COMPACT, REDUNDANT, and DYNAMIC row formats). --Tables with a COMPRESSED row format have a different physical page size than uncompressed tables. --Therefore, compressed tables cannot coexist in the same tablespace as uncompressed tables --没有指定 FILE_BLOCK_SIZE,不能存储压缩表 mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE test_ts ROW_FORMAT=COMPRESSED; ERROR 1478 (HY000): InnoDB: Tablespace `test_ts` cannot contain a COMPRESSED table --修改表空间属性 mysql> drop tablespace test_ts; Query OK, 0 rows affected (0.04 sec) mysql> CREATE TABLESPACE test_ts ADD DATAFILE '/tmp/testts.ibd' FILE_BLOCK_SIZE=8192 ENGINE=INNODB; Query OK, 0 rows affected (0.14 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE test_ts ROW_FORMAT=COMPRESSED; Query OK, 0 rows affected (0.71 sec) --当表空间中有表存在时,必需先清空表,才能删除表空间 --Use DROP TABLESPACE to remove a general tablespace. All tables must be dropped from a general tablespace using DROP TABLE prior to dropping the tablespace mysql> drop tablespace test_ts; ERROR 1529 (HY000): Failed to drop TABLESPACE test_ts mysql> drop table t1; Query OK, 0 rows affected (0.25 sec) mysql> drop tablespace test_ts; Query OK, 0 rows affected (0.01 sec) --Tables with a COMPRESSED row format have a different physical page size than uncompressed tables. mysql> CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE test_ts ROW_FORMAT=DYNAMIC; ERROR 1478 (HY000): InnoDB: Tablespace `test_ts` uses block size 8192 and cannot contain a table with physical page size 16384 --If FILE_BLOCK_SIZE is equal innodb_page_size, the tablespace can only contain tables with an uncompressed row format (COMPACT, REDUNDANT, and DYNAMIC row formats) mysql> CREATE TABLESPACE test_ts ADD DATAFILE '/tmp/testts.ibd' FILE_BLOCK_SIZE=16384 ENGINE=INNODB; Query OK, 0 rows affected (0.09 sec) mysql> show variables like '%page_size%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | innodb_page_size | 16384 | | large_page_size | 0 | +------------------+-------+ mysql> CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE test_ts ROW_FORMAT=DYNAMIC; Query OK, 0 rows affected (0.07 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE test_ts ROW_FORMAT=compressed; ERROR 1478 (HY000): InnoDB: Tablespace `test_ts` cannot contain a COMPRESSED table