mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIM
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-27 23:05:30 浏览: 评论:0
本文章来给各位同学介绍关于mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别,希望此教程对各位有帮助.
mysql5.6数据库,代码如下:
- [BIGHD](root@127.0.0.1) [cm]> SELECT version();
- +------------+
- | version() |
- +------------+
- | 5.6.13-log |
- +------------+
- 1 ROW IN SET (0.02 sec)
- [BIGHD](root@127.0.0.1) [cm]> ALTER TABLE s__uk ADD `last_op_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
- Query OK, 0 ROWS affected (0.99 sec)
- Records: 0 Duplicates: 0 Warnings: 0
- [BIGHD](root@127.0.0.1) [cm]> SELECT id, last_op_time FROM s__uk LIMIT 1;
- +----+---------------------+
- | id | last_op_time |
- +----+---------------------+
- | 1 | 2013-10-10 10:17:57 |
- +----+---------------------+
- 1 ROW IN SET (0.00 sec)
mysql5.5数据库,代码如下:
- (root@localhost) [cm]> SELECT version();
- +------------+
- | version() |
- +------------+
- | 5.5.15-log |
- +------------+
- 1 ROW IN SET (0.00 sec)
- (root@localhost) [cm]> ALTER TABLE s__uk ADD `last_op_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
- Query OK, 2523 ROWS affected (0.99 sec)
- Records: 2523 Duplicates: 0 Warnings: 0
- (root@localhost) [cm]> SELECT last_op_time FROM s__uk LIMIT 1;
- +---------------------+
- | last_op_time |
- +---------------------+
- | 0000-00-00 00:00:00 |
- +---------------------+
- 1 ROW IN SET (0.00 sec)
另外,有没有考虑过如果只更新这个字段会怎样?会是指定的时间,还是自动生成的时间?代码如下:
- (root@localhost) [cm]> UPDATE s__uk SET last_op_time='2012-12-12 00:00:00' WHERE id=1;
- Query OK, 1 ROW affected (0.07 sec)
- ROWS matched: 1 Changed: 1 Warnings: 0
- (root@localhost) [cm]> SELECT id, last_op_time FROM s__uk LIMIT 1;
- +----+---------------------+ phpfensi.com
- | id | last_op_time |
- +----+---------------------+
- | 1 | 2012-12-12 00:00:00 |
- +----+---------------------+
- 1 ROW IN SET (0.01 sec)
猜对了木有?
PS:如何判断字段中是否有多字节字符(比如中文)?
CHARACTER_LENGTH(value) = length(value) 则不包含多字节字符.
length为字节Bytes长度,CHARACTER_LENGTH为字符characters长度.
PS2:mongodb find() 之后美化/格式化输出的函数是:db.tbl.find().pretty()
Tags: mysql5 5 timestamp DEFAULT
相关文章
- ·CentOS6.4安装配置mysql 5.6服务器方法(2014-09-24)
- ·MySQL5.6 Using a password on the command line interface can be insecure(2014-09-24)
- ·Mysql5.5 InnoDB存储引擎设置(2014-09-28)
- ·mysql5.6设置sql_mode方法详解(2014-09-28)
- ·MYSQL开启慢查询与mysql5.6开启慢查询出错(2014-10-01)
- ·MySQL5.5默认编码的设置修改方法详解(2014-10-02)
- ·Linux中MySql5手动安装方法详解(2014-10-04)
- ·linux中mysql 5.5二进制文件安装详解(2014-10-04)
- ·mysql5存储过程入门创建,删除,调用详解(2014-10-07)
- ·MySql 5.X创建用户并授权方法(2014-10-08)
- ·mysql5 插入中文乱码问题(2014-10-08)
- ·mysql5.5提示Could not initialize master info structure(2014-10-09)
- ·mysql5 sql-mode 引起的错误解决办法(2014-10-10)
- ·MySQL5的存储过程详细实例(2014-10-13)
- ·php调用mysql5存储过程方法(2014-10-14)
- ·MHA实现mysql5.6主从切换安装配置教程(2014-10-17)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)