InnoDB strict mode is similar to SQL strict mode. When it is enabled, certain InnoDB warnings become errors instead.
In MariaDB 10.2.2 and later, InnoDB strict mode is enabled by default.
InnoDB strict mode can be enabled or disabled by configuring the innodb_strict_mode
server system variable.
Its global value can be changed dynamically with SET GLOBAL
. For example:
SET GLOBAL innodb_strict_mode=ON;
Its value for the current session can also be changed dynamically with SET SESSION
. For example:
SET SESSION innodb_strict_mode=ON;
It can also be set in a server option group in an option file prior to starting up the server. For example:
[mariadb] ... innodb_strict_mode=ON
If InnoDB strict mode is enabled, and if a DDL statement is executed and invalid or conflicting table options are specified, then an error is raised. The error will only be a generic error that says the following:
ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options")
However, more details about the error can be found by executing SHOW WARNINGS
.
For example, the error is raised in the following cases:
KEY_BLOCK_SIZE
table option is set to a non-zero value, but the ROW_FORMAT
table option is set to some row format other than the COMPRESSED
row format. For example: SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) KEY_BLOCK_SIZE=4 ROW_FORMAT=DYNAMIC; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: cannot specify ROW_FORMAT = DYNAMIC with KEY_BLOCK_SIZE. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
KEY_BLOCK_SIZE
table option is set to a non-zero value, but the configured value is larger than either 16
or the value of the innodb_page_size
system variable, whichever is smaller. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) KEY_BLOCK_SIZE=16; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: KEY_BLOCK_SIZE=16 cannot be larger than 8. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
KEY_BLOCK_SIZE
table option is set to a non-zero value, but the innodb_file_per_table
system variable is not set to ON
. SET GLOBAL innodb_file_per_table=OFF; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) KEY_BLOCK_SIZE=4; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
KEY_BLOCK_SIZE
table option is set to a non-zero value, but it is not set to one of the supported values: [1, 2, 4, 8, 16]. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) KEY_BLOCK_SIZE=5; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+-----------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------------------------------------+ | Warning | 1478 | InnoDB: invalid KEY_BLOCK_SIZE = 5. Valid values are [1, 2, 4, 8, 16] | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+-----------------------------------------------------------------------+ 3 rows in set (0.000 sec)
ROW_FORMAT
table option is set to the COMPRESSED
row format, but the innodb_file_per_table
system variable is not set to ON
. SET GLOBAL innodb_file_per_table=OFF; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) ROW_FORMAT=COMPRESSED; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: ROW_FORMAT=COMPRESSED requires innodb_file_per_table. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
ROW_FORMAT
table option is set to a value, but it is not set to one of the values supported by InnoDB: REDUNDANT
, COMPACT
, DYNAMIC
, and COMPRESSED
. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) ROW_FORMAT=PAGE; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: invalid ROW_FORMAT specifier. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
KEY_BLOCK_SIZE
table option is set to a non-zero value or the ROW_FORMAT
table option is set to the COMPRESSED
row format, but the innodb_page_size
system variable is set to a value greater than 16k
. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) ROW_FORMAT=COMPRESSED; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+-----------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------------------------------------+ | Warning | 1478 | InnoDB: Cannot create a COMPRESSED table when innodb_page_size > 16k. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+-----------------------------------------------------------------------+ 3 rows in set (0.00 sec)
DATA DIRECTORY
table option is set, but the innodb_file_per_table
system variable is not set to ON
. SET GLOBAL innodb_file_per_table=OFF; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) DATA DIRECTORY='/mariadb'; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: DATA DIRECTORY requires innodb_file_per_table. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
DATA DIRECTORY
table option is set, but the table is a temporary table. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TEMPORARY TABLE tab ( id int PRIMARY KEY, str varchar(50) ) DATA DIRECTORY='/mariadb'; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: DATA DIRECTORY cannot be used for TEMPORARY tables. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
INDEX DIRECTORY
table option is set. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) INDEX DIRECTORY='/mariadb'; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: INDEX DIRECTORY is not supported | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
PAGE_COMPRESSED
table option is set to 1
, so InnoDB page compression is enabled, but the ROW_FORMAT
table option is set to some row format other than the COMPACT
or DYNAMIC
row formats. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) PAGE_COMPRESSED=1 ROW_FORMAT=COMPRESSED; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 140 | InnoDB: PAGE_COMPRESSED table can't have ROW_TYPE=COMPRESSED | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
PAGE_COMPRESSED
table option is set to 1
, so InnoDB page compression is enabled, but the innodb_file_per_table
system variable is not set to ON
. SET GLOBAL innodb_file_per_table=OFF; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) PAGE_COMPRESSED=1; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 140 | InnoDB: PAGE_COMPRESSED requires innodb_file_per_table. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
PAGE_COMPRESSED
table option is set to 1
, so InnoDB page compression is enabled, but the KEY_BLOCK_SIZE
table option is also specified. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) PAGE_COMPRESSED=1 KEY_BLOCK_SIZE=4; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 140 | InnoDB: PAGE_COMPRESSED table can't have key_block_size | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
PAGE_COMPRESSION_LEVEL
table option is set, but the PAGE_COMPRESSED
table option is set to 0
, so InnoDB page compression is disabled. SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) PAGE_COMPRESSED=0 PAGE_COMPRESSION_LEVEL=9; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 140 | InnoDB: PAGE_COMPRESSION_LEVEL requires PAGE_COMPRESSED | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.000 sec)
In MariaDB 10.2 and before, the error is raised in the following additional cases:
KEY_BLOCK_SIZE
table option is set to a non-zero value, but the innodb_file_format
system variable is not set to Barracuda
. SET GLOBAL innodb_file_format='Antelope'; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) KEY_BLOCK_SIZE=4; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 1478 | InnoDB: KEY_BLOCK_SIZE requires innodb_file_format > Antelope. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.00 sec)
ROW_FORMAT
table option is set to either the COMPRESSED
or the DYNAMIC
row format, but the innodb_file_format
system variable is not set to Barracuda
. SET GLOBAL innodb_file_format='Antelope'; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) ROW_FORMAT=COMPRESSED; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+-----------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------------------------------------+ | Warning | 1478 | InnoDB: ROW_FORMAT=COMPRESSED requires innodb_file_format > Antelope. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+-----------------------------------------------------------------------+ 3 rows in set (0.00 sec)
PAGE_COMPRESSED
table option is set to 1
, so InnoDB page compression is enabled, but the innodb_file_format
system variable is not set to Barracuda
. SET GLOBAL innodb_file_format='Antelope'; SET SESSION innodb_strict_mode=ON; CREATE OR REPLACE TABLE tab ( id int PRIMARY KEY, str varchar(50) ) PAGE_COMPRESSED=1; SHOW WARNINGS; ERROR 1005 (HY000): Can't create table `db1`.`tab` (errno: 140 "Wrong create options") SHOW WARNINGS; +---------+------+--------------------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------------------+ | Warning | 140 | InnoDB: PAGE_COMPRESSED requires innodb_file_format > Antelope. | | Error | 1005 | Can't create table `db1`.`tab` (errno: 140 "Wrong create options") | | Warning | 1030 | Got error 140 "Wrong create options" from storage engine InnoDB | +---------+------+--------------------------------------------------------------------+ 3 rows in set (0.00 sec)
If InnoDB strict mode is enabled, and if a table uses the COMPRESSED
row format, and if the table's KEY_BLOCK_SIZE
is too small to contain a row, then an error is returned by the statement.
If InnoDB strict mode is enabled, and if a table exceeds its row format's maximum row size, then InnoDB will return an error.
ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.
See Troubleshooting Row Size Too Large Errors with InnoDB for more information.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/innodb-strict-mode/