mysql sql_mode 汇总整理

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: -- ANSI 使sql符合标准sqlThis mode changes syntax and behavior to conform more closely to standard S...
-- ANSI 使sql符合标准sql
This mode changes syntax and behavior to conform more closely to standard SQL


-- STRICT_TRANS_TABLES 如果事务语句有错,则使事务失败
If a value could not be inserted as given into a transactional table, abort the statement


-- TRADITIONAL 使用error替代warning
this mode is “give an error instead of a warning” when inserting an incorrect value into a column


-- ALLOW_INVALID_DATES 允许非法日期
Do not perform full checking of dates. Check only that the month is in the range from 1 to 12 and the day is in the range from 1 to 31
This mode applies to DATE and DATETIME columns. It does not apply TIMESTAMP columns, which always require a valid date
With strict mode disabled, invalid dates such as '2004-04-31' are converted to '0000-00-00' and a warning is generated. With strict mode enabled, invalid dates generate an error.


-- ANSI_QUOTES 使双引号当在一个标识符,而不 是一个字符串标识
Treat "" as an identifier quote character (like the "`" quote character) and not as a string quote character
--启用 ANSI_QUOTES 表名加双引号正常执行
mysql>  SET sql_mode='ANSI_QUOTES';
Query OK, 0 rows affected (0.01 sec)
mysql> select "id",id from "t" limit 3;
+----+----+
| id | id |
+----+----+
|  1 |  1 |
|  2 |  2 |
+----+----+
3 rows in set (0.00 sec
--关闭 ANSI_QUOTES 表名加双引报错
mysql>  SET sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select "id",id from "t" limit 10;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"t" limit 10' at line 1


-- ERROR_FOR_DIVISION_BY_ZERO 决定被0整除是后的行为? 
If this mode is not enabled, division by zero inserts NULL and produces no warning.
If this mode is enabled, division by zero inserts NULL and produces a warning.
If this mode and strict mode are enabled, division by zero produces an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, division by zero inserts NULL and produces a warning.


-- HIGH_NOT_PRECEDENCE 控制 not 的优化级
The precedence of the NOT operator is such that expressions such as NOT a BETWEEN b AND c are parsed as NOT (a BETWEEN b AND c)
mysql> SET sql_mode = '';
mysql> SELECT NOT 1 BETWEEN -5 AND 5;
-> 0
mysql> SET sql_mode = 'HIGH_NOT_PRECEDENCE';
mysql> SELECT NOT 1 BETWEEN -5 AND 5;
-> 1



-- NO_AUTO_CREATE_USER 阻止grant自动创建用户,如果没有提供密码或空密码是不认的
Prevent the GRANT statement from automatically creating new user accounts if it would otherwise do so, unless authentication information is specified
The statement must specify a nonempty password using IDENTIFIED BY or an authentication plugin using IDENTIFIED WITH


-- NO_AUTO_VALUE_ON_ZERO 当插入null或0者是否对 AUTO_INCREMENT 产生下一个值
NO_AUTO_VALUE_ON_ZERO affects handling of AUTO_INCREMENT columns. Normally, you generate the next sequence number for the column by inserting either NULL or 0 into it. 
NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the next sequence number.


-- NO_DIR_IN_CREATE 在创建表或索引时是否忽略目录参数,注意如果主从的目录结构不同,则可使用此参数
When creating a table, ignore all INDEX DIRECTORY and DATA DIRECTORY directives. This option is useful on slave replication servers.


-- NO_ENGINE_SUBSTITUTION 当创建表或修改表时使用了一个非法或disable的存储引擎时,是否使用其它替代的引擎
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


-- NO_ZERO_DATE 控制00是否可做为一个日期类型
The NO_ZERO_DATE mode affects whether the server permits '0000-00-00' as a valid date. Its effect also depends on whether strict SQL mode is enabled.
If this mode is not enabled, '0000-00-00' is permitted and inserts produce no warning.
If this mode is enabled, '0000-00-00' is permitted and inserts produce a warning.
If this mode and strict mode are enabled, '0000-00-00' is not permitted and inserts produce an error, 
unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.

-- NO_ZERO_IN_DATE 控制在年份不为0,但月或天是否可为0,影响如上
The NO_ZERO_IN_DATE mode affects whether the server permits dates in which the year part is nonzero but the month or day part is 0


-- ONLY_FULL_GROUP_BY 使group操作符合标准聚合操作
Reject queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on (uniquely determined by) GROUP BY columns


-- PIPES_AS_CONCAT 使双竖线成为连接符,类似于postgresql和oracle中的||
Treat || as a string concatenation operator (same as CONCAT()) rather than as a synonym for OR.


-- STRICT_ALL_TABLES 使严格模式使用于所有的表,非法数据被拒绝,推荐启用
Enable strict SQL mode for all storage engines. Invalid data values are rejected

-- STRICT_TRANS_TABLES 使严格事务模式使用于所有的存储引擎,推荐启用
Enable strict SQL mode for transactional storage engines, and when possible for nontransactional storage engines


-- mysql还针对不同的数据库提供了组合模式
ANSI,DB2,ORACLE,POSTGRESQL,MSSQL

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1天前
|
SQL 关系型数据库 MySQL
MySQL中的基本SQL语句
以上列举的是MySQL中的一些基础而重要的SQL语句。它们不仅提供了数据操作的方法,同时也涵盖了数据库、表结构的变更,数据的增删改查,结果的排序和聚合,索引的管理以及用户权限的控制等方面。掌握这些基本的SQL语句对于任何使用MySQL的开发者来说是非常必要的。在实际应用中,由于项目要求和数据复杂性的不同,可能需要将这些基础语句组合起来使用,或者与函数、存储过程和触发器等高级功能一起配合使用,以实现各种复杂的业务逻辑。
10 2
|
6天前
|
SQL 关系型数据库 MySQL
SQL语句编写的练习(MySQL)
这篇文章提供了MySQL数据库中关于学生表、课程表、成绩表和教师表的建表语句、数据插入示例以及一系列SQL查询练习,包括查询、排序、聚合和连接查询等操作。
|
12天前
|
SQL 关系型数据库 MySQL
INSERT INTO t_a.tableName SELECT * FROM t_b.tableName 如何通过定义一个list对象,包含多个tableName,循环执行前面的sql,用MySQL的语法写
【8月更文挑战第7天】INSERT INTO t_a.tableName SELECT * FROM t_b.tableName 如何通过定义一个list对象,包含多个tableName,循环执行前面的sql,用MySQL的语法写
16 5
|
11天前
|
SQL 关系型数据库 MySQL
MySQL中一定要遵守的12个SQL规范
本文档提供了12条SQL编写和数据库管理的最佳实践建议,旨在帮助开发者提高SQL查询效率、增强数据库安全性及可维护性。
|
7天前
|
SQL 关系型数据库 MySQL
Go语言中进行MySQL预处理和SQL注入防护
在现代Web应用开发中,安全性至关重要。SQL注入是一种常见的攻击方式,攻击者可通过构造特殊SQL查询来非法访问或修改数据库数据。本文介绍如何利用Go语言中的预处理SQL语句来防范此类攻击。预处理不仅能提升安全性,还能提高性能并简化代码。通过使用`?`作为占位符,Go自动处理参数转义,有效避免SQL注入。此外,文章还提供了连接MySQL数据库、执行预处理查询以及最佳实践的示例代码。务必遵循这些指导原则,确保应用程序的安全性。
16 0
|
8天前
|
SQL 存储 Oracle
MySQL 项目中 SQL 脚本更新、升级方式,防止多次重复执行
MySQL 项目中 SQL 脚本更新、升级方式,防止多次重复执行
18 0
|
12天前
|
SQL 缓存 关系型数据库
[mysql]状态检查常用SQL
[mysql]状态检查常用SQL
|
8月前
|
SQL 存储 关系型数据库
MySQL下使用SQL命令进行表结构与数据复制实践
MySQL下使用SQL命令进行表结构与数据复制实践
117 0
|
SQL 关系型数据库 MySQL
MySQl数据库第八课-------SQL命令查询-------主要命脉2
MySQl数据库第八课-------SQL命令查询-------主要命脉
|
SQL 关系型数据库 MySQL
MySQl数据库第八课-------SQL命令查询-------主要命脉 1
MySQl数据库第八课-------SQL命令查询-------主要命脉

热门文章

最新文章