mysql SQL_MODE 参数作用 _MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 1937 | 回复: 0   主题: mysql SQL_MODE 参数作用         下一篇 
darkhorse
注册用户
等级:新兵
经验:66
发帖:9
精华:0
注册:2014-4-20
状态:离线
发送短消息息给darkhorse 加好友    发送短消息息给darkhorse 发消息
发表于: IP:您无权察看 2015-1-4 16:48:23 | [全部帖] [楼主帖] 楼主

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)


可以看出,系统不支持的存储引擎以及不存在的存储引擎或者该存储引擎不支持表列特性的均不能创建成功。

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论