如何使用 Barracuda 文件格式创建 table

How to create a table using the Barracuda file format

因为我需要几个 mediumtext 字段,所以我需要 barracuda 文件格式。有很多关于如何将现有羚羊 table 转换为梭鱼的文章和视频,但 none 关于如何使用梭鱼创建新的 table 的文章和视频。使用 MariaDB 可以轻松做到这一点吗?如果可能,我想使用 docker 容器。

尝试:

MariaDB [_]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.1.23-MariaDB |
+-----------------+
1 row in set (0.00 sec)

MariaDB [_]> SHOW VARIABLES LIKE 'innodb_file_format';
+--------------------+----------+
| Variable_name      | Value    |
+--------------------+----------+
| innodb_file_format | Antelope |
+--------------------+----------+
1 row in set (0.01 sec)

MariaDB [_]> CREATE TABLE `barracuda_table` (`col` MEDIUMTEXT) ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

MariaDB [_]> SHOW WARNINGS;
+---------+------+--------------------------------------------------------------------+
| Level   | Code | Message                                                            |
+---------+------+--------------------------------------------------------------------+
| Warning | 1478 | InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_format > Antelope. |
| Warning | 1478 | InnoDB: assuming ROW_FORMAT=COMPACT.                               |
+---------+------+--------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [_]> SELECT ROW_FORMAT
    -> FROM `information_schema`.`tables`
    -> WHERE `TABLE_SCHEMA` = DATABASE() AND
    ->       `TABLE_NAME` = 'barracuda_table';
+------------+
| ROW_FORMAT |
+------------+
| Compact    |
+------------+
1 row in set (0.00 sec)

MariaDB [_]> DROP TABLE `barracuda_table`;
Query OK, 0 rows affected (0.00 sec)

MariaDB [_]> SET @@GLOBAL.innodb_file_format = 'Barracuda';
Query OK, 0 rows affected (0.00 sec)

MariaDB [_]> SHOW VARIABLES LIKE 'innodb_file_format';
+--------------------+-----------+
| Variable_name      | Value     |
+--------------------+-----------+
| innodb_file_format | Barracuda |
+--------------------+-----------+
1 row in set (0.00 sec)

MariaDB [_]> CREATE TABLE `barracuda_table` (`col` MEDIUMTEXT) ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.00 sec)

MariaDB [_]> SELECT ROW_FORMAT
    -> FROM `information_schema`.`tables`
    -> WHERE `TABLE_SCHEMA` = DATABASE() AND
    ->       `TABLE_NAME` = 'barracuda_table';
+------------+
| ROW_FORMAT |
+------------+
| Dynamic    |
+------------+
1 row in set (0.00 sec)

MariaDB [_]> SELECT `NAME`, `FILE_FORMAT`, `ROW_FORMAT`
    -> FROM `information_schema`.`INNODB_SYS_TABLES`
    -> WHERE `NAME` = '_/barracuda_table';
+-------------------+-------------+------------+
| NAME              | FILE_FORMAT | ROW_FORMAT |
+-------------------+-------------+------------+
| _/barracuda_table | Barracuda   | Dynamic    |
+-------------------+-------------+------------+
1 row in set (0.00 sec)

XtraDB/InnoDB Storage Formats

在 5.6(MariaDB 10.0 和 10.1)中很乱:

SET GLOBAL innodb_file_format=Barracuda;
SET GLOBAL innodb_file_per_table=1;
SET GLOBAL innodb_large_prefix=1;     -- optional (if you also need wide indexes)
ALTER TABLE tbl ROW_FORMAT=DYNAMIC;

它可能在 5.7 (MariaDB 10.2) 中正确默认。