Difference between MySQL 5.5 and 5.6 timestamp field DEFAULT current_timestamp on UPDATE current_timestamp

Source: Internet
Author: User
Tags mongodb find

mysql5.6 Database:

The code is as follows Copy Code
[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 CURR Ent_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 Database:

  code is as follows copy code

(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)

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

The code is as follows Copy Code
(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;
+----+---------------------+
| ID | Last_op_time |
+----+---------------------+
| 1 | 2012-12-12 00:00:00 |
+----+---------------------+
1 ROW in SET (0.01 sec)

Guess what, wood?

Ps:
How do I determine if there are multibyte characters in a field (such as Chinese)?

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

Length is the byte bytes length, Character_length is the character characters length.

PS2:
MongoDB Find ()

Then the function of beautifying/formatting the output is:
Db.tbl.find (). Pretty ()

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.