当前位置:网站首页>sql_mode严格模式(ANSI/TRADITIONAL/STRICT_TRANS_TABLES)
sql_mode严格模式(ANSI/TRADITIONAL/STRICT_TRANS_TABLES)
2022-07-27 05:04:00 【树迷了路】
ANSI模式:宽松模式,对插入数据进行校验,如果不符合定义类型或长度,对数据类型调整或截断保存,报warning警告
TRADITIONAL 模式:严格模式,当向mysql数据库插入数据时,进行数据的严格校验,保证错误数据不能插入,报error错误。用于事物时,会进行事物的回滚。
STRICT_TRANS_TABLES模式:严格模式,进行数据的严格校验,错误数据不能插入,报error错误。
查看sql_mode
mysql> select @@sql_mode;
+--------------------------------------------+
| @@sql_mode |
+--------------------------------------------+
| NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+临时变更为严格模式(关闭重启数据库后会失效)
mysql> set sql_mode='TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)
mysql> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+------------------------------------------------------------------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------------------------------------------------------------------+永久变更
在my.ini文件中添加或更改下列代码
非严格模式
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
严格模式
sql-mode="TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
或
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"严格模式对insert创建用户的影响
在mysql库的user表中插入一条记录
insert into mysql.user(user,host,password) values ('hello','localhost',password('world123'));如果当前mysql数据库的sql-mode设置为了严格检查(如TRADITIONAL/STRICT_TRANS_TABLES),则无法使用上述方法插入数据,如果sql-mode已经设置为严格检查,使用上述语句时可能会出现类似如下错误:
ERROR 1364 (HY000): Field ‘ssl_cipher’ doesn’t have a default value
边栏推荐
- Introduction of C language base conversion and original complement inverse code point operation
- Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()
- js进阶知识—函数
- 【codeforces 1695C Zero Path】DP
- Seckill system design
- 页面的配置
- First knowledge of C language -- what is C language
- JS中是如何使用for..of来遍历对象
- 程序环境和预处理(下):#define、#undef、命令行编译、条件编译、文件包含(超全整理,建议收藏!!!
- JS中数组的遍历方法有哪些
猜你喜欢

初识C语言——什么是C语言

Looking at the PK of alphago and Li Shishi from a deep perspective

Li Hongyi machine learning team learning punch in activity day02 --- return

Li Hongyi machine learning team learning punch in activity day04 - Introduction to deep learning and back propagation mechanism

如何将Excel表格中的多列内容合并到一列

pytorch安装新坑

DNSmasq使用总结

流程控制-分支

Li Hongyi machine learning team learning punch in activity day05 --- skills of network design

Flask请求数据获取与响应
随机推荐
JS中什么是DOM和BOM
下载url-loader,用limit指定图片大小后,显示不出图片
Day3 ---Flask 状态保持,异常处理与请求钩子
JS中for...of和for...in的区别
JS中&&(与)和||(或)操作符的返回值
函数和箭头函数
页面布局中元素定位的几种方式
后台品牌管理功能实现
pytorch安装新坑
js基础练习题
用户管理-分页
My first blog
进制的特性
[codeforces round 800 D question fake plastic trees] greedy on the tree
JS中原型及原型链
Time complexity and space complexity
Introduction to C language
权限的配置,组件传值
JS中apply、call、bind的区别
JS中数组的遍历方法有哪些