码迷,mamicode.com
首页 > 数据库 > 详细

MySQL sql_mode设置

时间:2017-07-30 10:12:52      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:default   配置   csdn   int   www.   comment   查看   engine   概率   

在MySQL5.7版本中创建表

CREATE TABLE `investor_seat` (
  `id` int(11) NOT NULL AUTO_INCREMENT ,
  `investorId` int(11) NOT NULL  COMMENT ‘投资人id‘,
  `seatId` int(11) NOT NULL  COMMENT ‘席位id‘,
  `maybe` float NOT NULL COMMENT ‘席位归属某帮派或者某人的概率‘,
  `investorName` varchar(28) NOT NULL COMMENT ‘投资人名含机构‘,
  `seatName` varchar(108) NOT NULL COMMENT ‘席位名‘,
  `status` TINYINT NOT NULL DEFAULT 0 COMMENT ‘投资人席位状态‘,
  `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updateTime` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARSET = utf8;

注意updateTime字段,会在创建的时候报错:

[Err] 1067 - Invalid default value for ‘updateTime‘

查找了原因,是要设置sql_mode

查看MySQL的sql_mode配置:

mysql> show variables like ‘sql_mode‘;
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value
                                    |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| sql_mode      | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

将mysql安装文件里面的my-default.ini(windows)//etc/my.cnf(Linux)里面添加设置:

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

http://www.nowck.com/archives/70.html

http://blog.csdn.net/wyzxg/article/details/8787878

MySQL sql_mode设置

标签:default   配置   csdn   int   www.   comment   查看   engine   概率   

原文地址:http://www.cnblogs.com/hongdada/p/7258067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!