博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql sql_mode 之 NO_ENGINE_SUBSTITUTION
阅读量:6756 次
发布时间:2019-06-26

本文共 5531 字,大约阅读时间需要 18 分钟。

知识储备:

  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会支持报错。

 

转载地址:http://qkweo.baihongyu.com/

你可能感兴趣的文章
Fegla and the Bed Bugs 二分
查看>>
linux 文本处理
查看>>
swoole重启机制(转载)
查看>>
hadoop day 1
查看>>
HDU 1251 统计难题
查看>>
用javascript脚本实现微信定时发送信息
查看>>
MongoDB学习笔记(四) 用MongoDB的文档结构描述数据关系
查看>>
[Windows Azure] Data Management and Business Analytics
查看>>
java面试题07
查看>>
什么是面向对象思想
查看>>
Quick-cocos2d-x3.3 Study (十六)--------- 碰撞检测,事件监听,设置掩码
查看>>
tomcat 安装
查看>>
C#调用c++创建的dll
查看>>
12.02个人博客
查看>>
Notification通知代码简洁使用
查看>>
UIView 动画
查看>>
ssh加密公私钥
查看>>
快速部署Python应用:Nginx+uWSGI配置详解
查看>>
mybatis-generator生成数据对象
查看>>
java Queue中 add/offer,element/peek,remove/poll区别
查看>>