The difference between MySQL 5.5 and 5.6 timestamp field DEFAULT current_timestamp on UPDATE current_timestamp

Source: Internet
Author: User
Tags mongodb find

Http://www.111cn.net/database/mysql/55392.htm

This article is to give you the difference between MySQL 5.5 and 5.6 timestamp field DEFAULT current_timestamp on UPDATE current_timestamp, I hope this tutorial will be helpful to you.

mysql5.6 Database:

The code is as follows Copy Code
[bighd" ([email protected] ) [cm]> SELECT version ();
+------------+
| version ()   |
+------------+
| 5.6.13-log |
+------------+
1 ROW in SET (0.02 sec)
 
[BIGHD] ([email protected]) [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] ([email& Nbsp;protected]) [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 Database:

The code is as follows Copy Code

([email protected]) [cm]> SELECT version ();
+------------+
| Version () |
+------------+
| 5.5.15-log |
+------------+
1 ROW in SET (0.00 sec)

([email protected]) [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

([email protected]) [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)

Also, have you ever considered what would happen if you only update this field? Will it be the specified time, or is it automatically generated?

copy code
([email protected]) [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
 
([EMAIL PR Otected]) [cm]> SELECT ID, last_op_time from s__uk  LIMIT 1;
+----+---------------------+
| id | last_op_time        |
+----+---------------------+
|  1 | 2012-12-12 00:00:00 |
+----+---------------------+
1 ROW in SET (0.01 sec)

Did you get the right wood?

Ps:
How do I tell if a field has multibyte characters (such as Chinese)?

Character_length (value) = LENGTH (value) does not contain multibyte characters.

Length is a byte bytes long and character_length is the character characters length.

PS2:
MongoDB Find ()

After that, the function to beautify/format the output is:
Db.tbl.find (). Pretty ()

? http://www.111cn.net/database/mysql/55392.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.