{"id":4158,"date":"2020-08-27T12:01:11","date_gmt":"2020-08-27T04:01:11","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=4158"},"modified":"2020-08-27T12:01:11","modified_gmt":"2020-08-27T04:01:11","slug":"timestamp","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=4158","title":{"rendered":"[ Mysql ] &#8211; TIMESTAMP \u7cbe\u5ea6\u554f\u984c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u53c8\u767c\u751f\u7684\u610f\u6599\u4e4b\u5916\u7684\u6642\u9593\u7cbe\u5ea6\u554f\u984c\uff0c\u5728 Mysql \u4e2d\u6642\u9593\u7684\u7cbe\u5ea6\u53ea\u5230\u79d2\uff0c\u5982\u679c\u4f60\u8981\u5230\u6beb\u79d2\u5c31\u4e00\u5b9a\u8981\u4f7f\u7528 TIMESTAMP ,\u4f46 TIMESTAMP \u9810\u8a2d\u503c\u5982\u679c\u4f60\u8a2d CURRENT_TIMESTAMP \u5176\u5be6\u4e5f\u662f\u53ea\u6709\u5230\u79d2\uff0c\u4f60\u9700\u8981\u8a2d\u6210 CURRENT_TIMESTAMP(3) \u6216 CURRENT_TIMESTAMP(6) \u4f9d\u4f60\u7684\u9700\u6c42\u53bb\u8a2d\u4f60\u8981\u7684\u7cbe\u5ea6\u3002<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u5728cli\u4e0b<\/p>\n\n\n<pre class=\"wp-block-code\"><code>select CURRENT_TIMESTAMP(3);<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">2020-08-27 11:40:33.896<\/p>\n\n\n<pre class=\"wp-block-code\"><code>select CURRENT_TIMESTAMP(6);<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">2020-08-27 11:40:33.909491<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u5efa\u7acb\u8cc7\u6599\u8868\u6307\u4ee4\u78bc<\/p>\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE IF NOT EXISTS `test`\n        (id varchar(30) NOT NULL,\n        time TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3),\n        PRIMARY KEY (id));<\/code><\/pre>\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE IF NOT EXISTS `test`\n        (id varchar(30) NOT NULL,\n        time TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),\n        PRIMARY KEY (id));<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u73fe\u6709\u8cc7\u6599\u8868<\/p>\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE `test` CHANGE `time` `time` TIMESTAMP(3) NULL DEFAULT CURRENT_TIMESTAMP(3);<\/code><\/pre>\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE `test` CHANGE `time` `time` TIMESTAMP(6) NULL DEFAULT CURRENT_TIMESTAMP(6);<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u6709\u4f7f\u7528 phpmyadmin \u5728\u5099\u4efd\u8cc7\u6599\u6642 \u532f\u51fa\u7684\u6642\u5019<\/p>\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE `test` (\n  `id` varchar(30) NOT NULL,\n  `time` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u5efa\u7acb\u8cc7\u6599\u8868\u7684\u8a9e\u6cd5\u6703\u6709\u4e2d\u65b7<br \/>\u4f46\u8cc7\u6599\u9084\u662f\u6709\u5b8c\u6574\u7684\u532f\u51fa<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u53c3\u8003\u7db2\u5740\uff1a<a href=\"https:\/\/stackoverflow.com\/questions\/23671222\/mysql-default-value-for-timestamp3\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/stackoverflow.com\/questions\/23671222\/mysql-default-value-for-timestamp3<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c8\u767c\u751f\u7684\u610f\u6599\u4e4b\u5916\u7684\u6642\u9593\u7cbe\u5ea6\u554f\u984c\uff0c\u5728 Mysql \u4e2d\u6642\u9593\u7684\u7cbe\u5ea6\u53ea\u5230\u79d2\uff0c\u5982\u679c\u4f60\u8981\u5230\u6beb\u79d2\u5c31\u4e00\u5b9a\u8981\u4f7f\u7528 TIMESTAMP ,\u4f46 TIMESTAMP \u9810\u8a2d\u503c\u5982\u679c\u4f60\u8a2d CURRENT_TIMESTAMP \u5176\u5be6\u4e5f\u662f\u53ea\u6709\u5230\u79d2\uff0c\u4f60\u9700\u8981\u8a2d\u6210 CURRENT_TIMESTAMP(3) \u6216 CURRENT_TIMESTAMP(6) \u4f9d\u4f60\u7684\u9700\u6c42\u53bb\u8a2d\u4f60\u8981\u7684\u7cbe\u5ea6\u3002<\/p>\n","protected":false},"author":1,"featured_media":1867,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[402,565,934,975],"class_list":["post-4158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-mysql","tag-timestamp","tag-934","tag-975","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/4158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4158"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/4158\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/1867"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}