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