mysql 5.6 datatime 性能_mysql5.6 datetime一些测试结果

会写入全零的数据,

(1)最后一位微秒写入1,其余全零

mysql> select * from user;

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-01 00:00:00.000000 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

| 2015-03-15 12:12:15.000000 | 222 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

| 2015-03-15 12:12:15.000000 | 444 | 2015-03-15 12:12:15.22001 | 2015-03-15 12:12:15.4711 | 2015-03-15 12:12:15.481 |

| 2015-03-15 12:12:15.000000 | ccc | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

4 rows in set (0.00 sec)

mysql> update user set gmt_create = "00-00-00 00:00:00.000001" where name = "111";

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user;

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 2000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

| 2015-03-15 12:12:15.000000 | 222 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

| 2015-03-15 12:12:15.000000 | 444 | 2015-03-15 12:12:15.22001 | 2015-03-15 12:12:15.4711 | 2015-03-15 12:12:15.481 |

| 2015-03-15 12:12:15.000000 | ccc | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

4 rows in set (0.00 sec)(2)4位年数字写成3个0,结果是4位全0的年

mysql> update user set gmt_create = "000-00-00 00:00:00.000001" where name = "111";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

1 row in set (0.00 sec)

(3)4位年数写成两个0,居然年份写成了2000,惊讶!!

mysql> update user set gmt_create = "00-00-00 00:00:00.000001" where name = "111";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 2000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+(4)4位年数写成一个0,再试试,结果是年字段是4个0

mysql> update user set gmt_create = "0-00-00 00:00:00.000001" where name = "111";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

(5)月和日的写成一个0,试试年月会自动补全成00:00格式

mysql> update user set gmt_create = "0000-0-0 00:00:00.000001" where name = "111";

Query OK, 0 rows affected (0.00 sec)

Rows matched: 1 Changed: 0 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

(6)时分秒分别改成一个0写入,结果时分秒也会补全成两个0的格式

mysql> update user set gmt_create = "0-00-00 0:0:0.000001" where name = "111";

Query OK, 0 rows affected (0.00 sec)

Rows matched: 1 Changed: 0 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000001 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

(7)毫秒字段写5个0,结果会补全成数据类型声明的datetime(6)的

mysql> update user set gmt_create = "0000-0-0 00:00:00.00000" where name = "111";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000000 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

(8)精度会精确到毫秒

mysql> update user set gmt_create = "0-00-00 0:0:0.00001" where name = "111";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where name="111";

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| gmt_create | name | gmt_modify | gmt_4 | gmt_3 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

| 0000-00-00 00:00:00.000010 | 111 | 2015-03-15 12:12:15.00000 | 2015-03-15 12:12:15.0000 | 2015-03-15 12:12:15.000 |

+----------------------------+------+---------------------------+--------------------------+-------------------------+

回答: MySQL中的datetime格式是一种用于存储日期和时间的数据类型。它的存储范围没有限制,从 '1000-01-01 00:00:00.000000' 到 '9999-12-31 23:59:59.999999'。\[2\]与此不同,timestamp类型在存储时会将客户端插入的时间按照当前的时区转化为UTC(世界标准时间)进行存储,并在查询时按照客户端的时区进行转化后返回。timestamp的存储范围较小,从 '1970-01-01 00:00:01.000000' 到 '2038-01-19 03:14:07.999999',因为它是以整型int数据存储的,而int有大小范围限制。\[2\]如果在timestamp字段中插入NULL值,它会自动存储当前时间,而datetime字段会存储NULL值。\[3\] 如果你想在前端显示特定的日期时间格式,你可以在连接数据库时添加一个属性dateStrings: true,这样TIMESTAMP、DATETIME和DATE类型的数据将以字符串的形式返回,例如'2018-12-14 14:53:05'。\[1\]这样你就可以得到你需要的格式了。 #### 引用[.reference_title] - *1* [[node.js] mysql datatime格式转换为YYYY-MM-DD hh:mm:ss 字符串形式](https://blog.csdn.net/towrabbit/article/details/85029047)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [mysqldatatimetimestamp之间的区别](https://blog.csdn.net/qqw666666/article/details/125292949)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值