mysql sql_mode 之 NO_ENGINE_SUBSTITUTION

來源:互聯網
上載者:User

標籤:

知識儲備:

  1、mysql 有眾多的儲存引擎,然而只有一個預設的儲存引擎,通常來說它是innodb

  2、mysql 可以通過sql_mode 來控制mysql 資料庫的行為,今天我們要講的就是no_engine_substitution

  3、no_engine_subtitution的作用:mysql 在create table 時可以指定engine子句;這個engine子句用於指定表的儲存引擎,那麼問題就來了。

     如果我把引擎指定成一個並不存在的引擎!這個時候mysql可以有兩種行為供選擇 1、直接報錯;2、把表的儲存引擎替換成innodb

 

例子:

  1、環境檢查(查看mysql所支援的儲存引擎,sql_mode模式)

  001:儲存引擎,由可以看出在這個mysql上不支援federated 引擎

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         || PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         || ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         || InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        || FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+9 rows in set (0.00 sec)

  002:sql_mode

mysql> show variables like ‘sql_mode‘;+---------------+---------------------+| Variable_name | Value               |+---------------+---------------------+| sql_mode      | STRICT_TRANS_TABLES |+---------------+---------------------+1 row in set (0.00 sec)

  003:測試

mysql> create table t(x int) engine=federated;Query OK, 0 rows affected, 2 warnings (0.11 sec)mysql> show create table t;+-------+--------------------------------------------------------------------------------------+| Table | Create Table                                                                         |+-------+--------------------------------------------------------------------------------------+| t     | CREATE TABLE `t` (  `x` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1 |+-------+--------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> 

結論001:在sql_mode中不包涵no_engine_subtitution 且create table 中engine子句指定的儲存引擎不被支援時,mysql會把表的引擎改為innodb。

 

例子:

  在sql_mode包涵有no_engine_subtitution時

  引擎支援情況:

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         || PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         || ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         || InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        || FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+9 rows in set (0.00 sec)

  sql_mode情況:

mysql> show variables like ‘sql_mode‘;+---------------+--------------------------------------------+| Variable_name | Value                                      |+---------------+--------------------------------------------+| sql_mode      | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |+---------------+--------------------------------------------+1 row in set (0.00 sec)

  測試:

mysql> create table t2(x int) engine=federated;ERROR 1286 (42000): Unknown storage engine ‘federated‘

結論002:當sql_mode中包涵no_engine_subtitution時,如果create table 時指定的engine項不被支援,這個時候mysql會支援報錯。

 

mysql sql_mode 之 NO_ENGINE_SUBSTITUTION

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.