General tablespace is new type of InnoDB tablespace which introduced in MySQL 5.7.6.
1. General tablespace stores several tables like shared tablespace.
2. General tablespace supports Antelope and Barracuda file format.
3. General tablespace file uses .ibd extention.
4. You can create table in general tablespace executing CREATE TABLE ... TABLESPACE command.
4. You can move table each tablespace executing ALTER TABLE ... TABLESPACE command.
Create General Tablespace
CREATE TABLESPACE tablespace_name
ADD DATAFILE ‘file_name’
[FILE_BLOCK_SIZE = value]
[ ENGINE [=] engine_name ]
for example,
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE ‘ts1.ibd’ Engine=InnoDB ;
You can specify a particular directory path.
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE ‘./my_tablespace/ts1.ibd’ Engine=InnoDB ;
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE ‘/my/tablespace/directory/ts1/ibd’ Engine=InnoDB ;
Create table in General tablespace
After create general tablespace, you can create or move table in general tablespace with this command.
CREATE TABLE:
mysql> CREATE TABLE t1 ( c1 INT PRIMARY KEY ) TABLESPACE ts1 ROW_FORMAT = COMPACT ;
or
ALTER TABLE:
mysql> ALTER TABLE t2 TABLESPACE ts1;
General tablespace supports all row format - REDUNDANT, COMPACT, DYNAMIC, COMPRESSED .
When compressed table stored general tablespace, which tablespace can not store non-compressed table, because each table has different page size.
General tablespace must be specified with FILE_BLOCK_SIZE option for storing compressed table. ( ROW_FORMAT = COMPRESSED )
For example, innodb_page_size is 16K , FILE_BLOCK_SIZE is 8K , then KEY_BLOCK_SIZE of the table must be 8.
Follow the examples.
First, create general tablespace. And storing compressed table.
CREATE TABLESPACE `ts2` ADD DATAFILE ‘ts2.ibd’ FILE_BLOCK_SIZE = 8192 Engine = InnoDB ;
CREATE TABLE t4 ( c1 INT PRIMARY KEY ) TABLESPACE t2 ROW_FORMAT = COMPRESSED KEY_BLOCK_SIZE= 8 ;
This general tablespace's FILE_BLOCK_SIZE is 8192, and compressed table has 8KB KEY_BLOCK_SIZE.
Drop General tablespace
When drop general tablespace, execute "DROP TABLESPACE ..." command.
General tablespace will be dropped must be empty.
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts10 Engine=InnoDB;
Query OK, 0 rows affected (0.02 sec)
mysql> DROP TABLE t1;
Query OK, 0 rows affected (0.01 sec)
mysql> DROP TABLESPACE ts1;
Query OK, 0 rows affected (0.01 sec)