{"id":35181,"date":"2024-11-26T17:16:12","date_gmt":"2024-11-26T09:16:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35181\/"},"modified":"2024-11-26T17:16:12","modified_gmt":"2024-11-26T09:16:12","slug":"mysql-%e4%b8%ad%e6%8f%92%e5%85%a5%e6%9b%b4%e6%96%b0%e6%97%b6%e9%97%b4%e6%88%b3%ef%bc%9a%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%ae%8c%e6%88%90%e6%97%b6%e9%97%b4%e6%88%b3%e6%97%a9%e4%ba%8e%e5%bc%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35181\/","title":{"rendered":"MySQL \u4e2d\u63d2\u5165\u66f4\u65b0\u65f6\u95f4\u6233\uff1a\u5982\u4f55\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063359222234.jpg\" class=\"aligncenter\" title=\"MySQL \u4e2d\u63d2\u5165\u66f4\u65b0\u65f6\u95f4\u6233\uff1a\u5982\u4f55\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e2d\u63d2\u5165\u66f4\u65b0\u65f6\u95f4\u6233\uff1a\u5982\u4f55\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e2d\u63d2\u5165\u548c\u66f4\u65b0\u65f6\u95f4\u6233\u7684\u9677\u9631<\/strong><\/p>\n<p>\u6211\u4eec\u5728\u63d2\u5165\u6570\u636e\u65f6\u8bbe\u7f6e\u4e86\u5f00\u59cb\u65f6\u95f4\u6233\u4e3a new date()\uff0c\u5e76\u542f\u52a8\u5f02\u6b65\u65b9\u6cd5\u6765\u66f4\u65b0\u8be5\u6570\u636e\u7684\u5b8c\u6210\u65f6\u95f4\u6233\u3002\u7136\u800c\uff0c\u6709\u65f6\u6211\u4eec\u4f1a\u9047\u5230\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\u7684\u610f\u5916\u60c5\u51b5\u3002<\/p>\n<p><strong>\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u9020\u6210\u6b64\u95ee\u9898\u7684\u539f\u56e0\u53ef\u80fd\u662f\uff1a<\/p>\n<ul>\n<li> <strong>\u5f02\u6b65\u6267\u884c\uff1a<\/strong>\u5f02\u6b65\u65b9\u6cd5\u53ef\u80fd\u5728 sql \u67e5\u8be2\u4e4b\u524d\u6267\u884c\uff0c\u5bfc\u81f4\u66f4\u65b0\u65f6\u95f4\u6233\u53d1\u751f\u5728\u63d2\u5165\u4e4b\u524d\u3002<\/li>\n<li> <strong>\u624b\u52a8\u8bbe\u7f6e\u65f6\u95f4\u6233\uff1a<\/strong>\u5982\u679c\u6211\u4eec\u624b\u52a8\u8bbe\u7f6e\u65f6\u95f4\u6233\uff0c\u5219\u9700\u8981\u786e\u4fdd\u5728\u4e24\u6761\u8bed\u53e5\u4e2d\u4f7f\u7528\u76f8\u540c\u7684\u65f6\u95f4\u6e90\u3002<\/li>\n<\/ul>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5efa\u8bae\u4f7f\u7528\u6570\u636e\u5e93\u81ea\u5e26\u7684 now() \u51fd\u6570\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u4e24\u6761\u8bed\u53e5\u4f7f\u7528\u76f8\u540c\u7684\u65f6\u95f4\u6e90\uff0c\u4ece\u800c\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>-- \u63d2\u5165\u6570\u636e\u5e76\u8bbe\u7f6e\u5f00\u59cb\u65f6\u95f4\u6233\nINSERT INTO table (start_time) VALUES (NOW());\n\n-- \u542f\u52a8\u5f02\u6b65\u65b9\u6cd5\u66f4\u65b0\u5b8c\u6210\u65f6\u95f4\u6233\n\/\/ \u5f02\u6b65\u65b9\u6cd5\u4e2d\nUPDATE table SET finish_time = NOW() WHERE id = last_insert_id();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d\u63d2\u5165\u66f4\u65b0\u65f6\u95f4\u6233\uff1a\u5982\u4f55\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2d\u63d2\u5165\u548c\u66f4\u65b0\u65f6\u95f4\u6233\u7684\u9677\u9631 \u6211\u4eec\u5728\u63d2\u5165\u6570\u636e\u65f6\u8bbe\u7f6e\u4e86\u5f00\u59cb\u65f6\u95f4\u6233\u4e3a new date()\uff0c\u5e76\u542f\u52a8\u5f02\u6b65\u65b9\u6cd5\u6765\u66f4\u65b0\u8be5\u6570\u636e\u7684\u5b8c\u6210\u65f6\u95f4\u6233\u3002\u7136\u800c\uff0c\u6709\u65f6\u6211\u4eec\u4f1a\u9047\u5230\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\u7684\u610f\u5916\u60c5\u51b5\u3002 \u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6848 \u9020\u6210\u6b64\u95ee\u9898\u7684\u539f\u56e0\u53ef\u80fd\u662f\uff1a \u5f02\u6b65\u6267\u884c\uff1a\u5f02\u6b65\u65b9\u6cd5\u53ef\u80fd\u5728 sql \u67e5\u8be2\u4e4b\u524d\u6267\u884c\uff0c\u5bfc\u81f4\u66f4\u65b0\u65f6\u95f4\u6233\u53d1\u751f\u5728\u63d2\u5165\u4e4b\u524d\u3002 \u624b\u52a8\u8bbe\u7f6e\u65f6\u95f4\u6233\uff1a\u5982\u679c\u6211\u4eec\u624b\u52a8\u8bbe\u7f6e\u65f6\u95f4\u6233\uff0c\u5219\u9700\u8981\u786e\u4fdd\u5728\u4e24\u6761\u8bed\u53e5\u4e2d\u4f7f\u7528\u76f8\u540c\u7684\u65f6\u95f4\u6e90\u3002 \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5efa\u8bae\u4f7f\u7528\u6570\u636e\u5e93\u81ea\u5e26\u7684 now() \u51fd\u6570\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u4e24\u6761\u8bed\u53e5\u4f7f\u7528\u76f8\u540c\u7684\u65f6\u95f4\u6e90\uff0c\u4ece\u800c\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\u7684\u60c5\u51b5\u3002 \u56e0\u6b64\uff0c\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a &#8212; \u63d2\u5165\u6570\u636e\u5e76\u8bbe\u7f6e\u5f00\u59cb\u65f6\u95f4\u6233 INSERT INTO table (start_time) VALUES (NOW()); &#8212; \u542f\u52a8\u5f02\u6b65\u65b9\u6cd5\u66f4\u65b0\u5b8c\u6210\u65f6\u95f4\u6233 \/\/ \u5f02\u6b65\u65b9\u6cd5\u4e2d UPDATE table SET finish_time = NOW() WHERE id = last_insert_id(); \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d\u63d2\u5165\u66f4\u65b0\u65f6\u95f4\u6233\uff1a\u5982\u4f55\u907f\u514d\u5b8c\u6210\u65f6\u95f4\u6233\u65e9\u4e8e\u5f00\u59cb\u65f6\u95f4\u6233\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35181","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35181"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35181\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}