文档章节

mysql 的 NO_ENGINE_SUBSTITUTION

xxj123gogo
 xxj123gogo
发布于 2017/08/23 16:46
字数 650
阅读 21
收藏 0

今天松问了一个问题, NO_ENGINE_SUBSTITUTION 是干啥的,这个还真没注意过以前。

研究了一下,原来这个是在创建表指定engine子句的时候,让mysql对此DDL做判断用的。看一个例子:

mysql> show variables like '%sql_mode%'; 
+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| sql_mode      | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
1 row in set (0.01 sec)

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                                     | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                             | NULL         | NULL | NULL       |
| InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

mysql> use test ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table t_e (it int ) engine=FEDERATE1;
ERROR 1286 (42000): Unknown storage engine 'FEDERATE1'  #FEDERATE1引擎不存在,直接报错。

当前 sql_mode="NO_ENGINE_SUBSTITUTION",表示不进行引擎替换。就是说,如果DDL的engine子句指定的引擎不存在,直接报错。

再看下面的例子。

mysql> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)

mysql> create table t_e (it int ) engine=FEDERATE1;
Query OK, 0 rows affected, 2 warnings (0.04 sec)


1 row in set (0.00 sec)
mysql> show warnings ;
+---------+------+---------------------------------------------+
| Level   | Code | Message                                     |
+---------+------+---------------------------------------------+
| Warning | 1286 | Unknown storage engine 'FEDERATE1'          |
| Warning | 1266 | Using storage engine InnoDB for table 't_e' | 
+---------+------+---------------------------------------------+
2 rows in set (0.00 sec)

mysql> show create table t_e;
+-------+-----------------------------------------------------------------------------------------+
| Table | Create Table                                                                            |
+-------+-----------------------------------------------------------------------------------------+
| t_e   | CREATE TABLE `t_e` (
  `it` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------+
#引擎已被替换成InnoDB

去掉 NO_ENGINE_SUBSTITUTION ,此时,依然指定一个不存在的引擎,mysql自动将引擎替换成默认的innodb引擎。

去掉 NO_ENGINE_SUBSTITUTION ,对于alter操作的行为是:alter操作并不成功。

mysql> show create table t_e;
+-------+-----------------------------------------------------------------------------------------+
| Table | Create Table                                                                            |
+-------+-----------------------------------------------------------------------------------------+
| t_e   | CREATE TABLE `t_e` (
  `it` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
#以前是MyISAM引擎。

mysql> alter table t_e engine=FEDERATE1;  #修改成不存在的FEDERATE1引擎
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 1

mysql> show warnings ;                  
+---------+------+------------------------------------+
| Level   | Code | Message                            |
+---------+------+------------------------------------+
| Warning | 1286 | Unknown storage engine 'FEDERATE1' |
+---------+------+------------------------------------+
1 row in set (0.00 sec)

mysql> show create table t_e;           
+-------+-----------------------------------------------------------------------------------------+
| Table | Create Table                                                                            |
+-------+-----------------------------------------------------------------------------------------+
| t_e   | CREATE TABLE `t_e` (
  `it` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | #引擎并没修改。
+-------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

如下是官网解释:

 NO_ENGINE_SUBSTITUTION

Control automatic substitution of the default storage engine when a statement such as CREATE TABLE or ALTER TABLE specifies a storage engine that is disabled or not compiled in.

The default SQL mode includes NO_ENGINE_SUBSTITUTION.

Because storage engines can be pluggable at runtime, unavailable engines are treated the same way:

With NO_ENGINE_SUBSTITUTION disabled, for CREATE TABLE the default engine is used and a warning occurs if the desired engine is unavailable. For ALTER TABLE, a warning occurs and the table is not altered.

With NO_ENGINE_SUBSTITUTION enabled, an error occurs and the table is not created or altered if the desired engine is unavailable.

© 著作权归作者所有

共有 人打赏支持
xxj123gogo
粉丝 0
博文 48
码字总数 65794
作品 0
其它
程序员
STRICT_TRANS_TABLES(存储引擎启用严格模式,非法数据值被拒绝)。

MySQL 1364 错误提示:#1364 - Field "details" doesn't have a default value。大概意思是:details字段没有默认的数值;也就是说我们没有为其分配数值,而表中此字段也没有设置默认值。这是...

fzxu_05
2015/09/25
2.3K
0
MySQL的sql_mode模式

MySQL 5.0 以上版本支持三种sqlmode模式:ANSI、TRADITIONAL和STRICTTRANS_TABLES。 ANSI ANSI模式:宽松模式,对插入数据进行校验,如果不符合定义类型或长度,对数据类型调整或截断保存,报...

运维的名义
01/23
0
0
mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘sss.month_id’ which is not functionally dependent on columns in GROUP BY clause; thi......

啃不动地大坚果
03/07
0
0
ubuntu16.04 mysql group报错ERROR 1055 (42000): Expression #1

ubuntu16.04 apache2.4 php7.0 mysql5.7 $ordergoods=db('ordergoods')->where('orderid','in',$orderidarr)->group('orderid')->having('id>0')->select();echo db('order_goods')->getLast......

Marhal
03/27
0
0
导入数据的时候,MYSQL 报错:Data too long for column

ERROR 1406 (22001): Data too long for column 解决方法 导入数据的时候,MYSQL 报错:Data too long for column 解决办法: 在my.ini里找到 sql-mode=”STRICTTRANSTABLES,NOAUTOCREATEUSER,......

雍雍_yoyo
2015/02/10
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

jquery创建类似于java的map

var map = {}; // Map map = new HashMap(); map[key] = value; // map.put(key, value); var value = map[key]; // Object value = map.get(key); var has = key in map; // boolean has = ......

SuperDabai
32分钟前
0
0
java大数据转换16进制转10进制

public static void main(String[] args) {String hex = "0xdbf3accc683297cf0000";BigInteger amount = new BigInteger(hex.substring(2), 16);System.out.println(amount);......

任梁荣
昨天
1
0
OSChina 周六乱弹 —— 目测我们程序员丁克的几率不大

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @真Skr小机灵鬼儿:8.13分享Jocelyn Pook/Russian Red的单曲《Loving Strangers》 《Loving Strangers》- Jocelyn Pook/Russian Red 手机党少...

小小编辑
昨天
9
3
TypeScript基础入门 - 函数 - 剩余参数

转载 TypeScript基础入门 - 函数 - 剩余参数 项目实践仓库 https://github.com/durban89/typescript_demo.gittag: 1.2.1 为了保证后面的学习演示需要安装下ts-node,这样后面的每个操作都能...

durban
昨天
1
0
OpenCV边缘检测算子原理总结及实现

1. 拉普拉斯算子 原理:是一种基于图像导数运算的高通线性滤波器。它通过二阶导数来度量图像函数的曲率。 拉普拉斯算子是最简单的各向同性微分算子,它具有旋转不变性。一个二维图像函数的拉...

漫步当下
昨天
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部