mysql 5.5 中,該值默認爲空值:
mysql> SELECT VERSION(); +------------+ | VERSION() | +------------+ | 5.5.29-log | +------------+ 1 row in set (0.00 sec) mysql> SHOW VARIABLES LIKE '%SQL_MODE%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | sql_mode | | +---------------+-------+ 1 row in set (0.00 sec)
mysql 5.6中:
mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 5.6.11 | +-----------+ 1 row in set (0.00 sec) mysql> SHOW VARIABLES LIKE '%SQL_MODE%'; +---------------+--------------------------------------------+ | Variable_name | Value | +---------------+--------------------------------------------+ | sql_mode | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | +---------------+--------------------------------------------+ 1 row in set (0.00 sec)
關於這兩個值的含義,我引用姜承堯http://weibo.com/insidemysql《mysql技術內幕:Innodb存儲引擎》這本書中的要丟安描述:
驗證NO_ENGINE_SUBSTITUTION:
mysql> SELECT VERSION(); +------------+ | VERSION() | +------------+ | 5.5.29-log | +------------+ 1 row in set (0.00 sec) mysql> SHOW ENGINES; +--------------------+---------+------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+------------------------------------------------------------+--------------+------+------------+ | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | +--------------------+---------+------------------------------------------------------------+--------------+------+------------+ 6 rows in set (0.00 sec) mysql> SELECT DATABASE(); +------------+ | DATABASE() | +------------+ | clovem | +------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE t1 (id int) ENGINE=clovem; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql> SHOW CREATE TABLE t1; +-------+--------------------------------------------------------------------------------------+ | Table | Create Table | +-------+--------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------+--------------------------------------------------------------------------------------+
可以看出,mysql5.5中,在創建表的時候任意指定一個存儲引擎,均不會報錯,只不過如果該存儲引擎系統不支持,則設置爲默認存儲引擎。下面看mysql5.6中設置了SQL_MODE的情況
mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 5.6.11 | +-----------+ 1 row in set (0.00 sec) mysql> SHOW ENGINES; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 9 rows in set (0.00 sec) mysql> CREATE TABLE t1 (id int) ENGINE=FEDERATED; ERROR 1286 (42000): Unknown storage engine 'FEDERATED' mysql> CREATE TABLE t2 (id int) ENGINE=clovem; ERROR 1286 (42000): Unknown storage engine 'clovem' mysql> CREATE TABLE t3 (id int) ENGINE=CSV; ERROR 1178 (42000): The storage engine for the table doesn't support nullable columns mysql> CREATE TABLE t3 (id int) ENGINE=MyISAM; Query OK, 0 rows affected (0.03 sec) mysql> SHOW TABLES; +----------------+ | Tables_in_test | +----------------+ | t3 | +----------------+ 1 row in set (0.00 sec)
可以看出,系統不支持的存儲引擎以及不存在的存儲引擎或者該存儲引擎不支持表列特性的均不能創建成功。