Mysql 5.5 and 5.6 timestamp fields DEFAULT CURRENT_TIMESTAMP ON UPDA

Source: Internet
Author: User
Tags mongodb find

This article will introduce the differences between mysql 5.5 and 5.6 timestamp fields 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] (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 | 10:17:57 |
+ ---- + --------------------- +
1 row in set (0.00 sec)
 


 
 
Mysql5.5 database:

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

In addition, have you considered how to update this field? Will it be the specified time or the automatic generation time?

The Code is as follows: Copy code
(Root @ localhost) [cm]> UPDATE s _ uk SET last_op_time = '2017-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 | 00:00:00 |
+ ---- + --------------------- +
1 row in set (0.01 sec)

Right?

PS:
How can I determine whether a field contains multi-byte characters (such as Chinese )?

CHARACTER_LENGTH (value) = length (value) does not contain multi-byte characters.

Length is the byte length, and CHARACTER_LENGTH is the character characters length.

PS2:
Mongodb find ()

The function for subsequent beautification/formatting 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.