{"id":150168,"date":"2020-09-02T19:09:59","date_gmt":"2020-09-02T11:09:59","guid":{"rendered":"http:\/\/4563.org\/?p=150168"},"modified":"2020-09-02T19:09:59","modified_gmt":"2020-09-02T11:09:59","slug":"jdbc-connection-url-string-%e4%b8%ad%e7%9a%84-servertimezone-%e7%9a%84%e4%bd%9c%e7%94%a8%e5%88%b0%e5%ba%95%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=150168","title":{"rendered":"JDBC connection URL string \u4e2d\u7684 serverTimezone \u7684\u4f5c\u7528\u5230\u5e95\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  JDBC connection URL string \u4e2d\u7684 serverTimezone \u7684\u4f5c\u7528\u5230\u5e95\u662f\u4ec0\u4e48\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <span><i><\/i> 17<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728MySQL \u65f6\u95f4\u201c\u4e0d\u6b63\u786e\u201d\u95ee\u9898 &#8211; V2EX\u4e2d\uff0c\u901a\u8fc7\u5728 connection URL string \u4e2d\u663e\u5f0f\u5730\u8bbe\u7f6e\u65f6\u533a\uff08 serverTimezone=Asia\/Shanghai \uff09\u89e3\u51b3\u4e86\u95ee\u9898\u3002<\/p>\n<p>\u4f46\u662f\u6211\u8fd8\u662f\u6709\u5f88\u591a\u7591\u95ee\u3002\u4e3a\u4ec0\u4e48\u201c\u5728 connection URL string \u4e2d\u8bbe\u7f6e\u65f6\u533a\u201d\u4f1a\u5c06\u6240\u8bbe\u7f6e\u65f6\u533a\u7684\u65f6\u95f4\u5b58\u50a8\u5230 MySQL \uff1f\u5230\u5e95\u662f\u54ea\u91cc\u8fdb\u884c\u8fd9\u6837\u7684\u5904\u7406\u7684\uff1f<\/p>\n<p>\u4ee5\u4e0b\u662f\u6211\u67e5\u9605\u7684\u4e00\u4e9b\u8d44\u6599\uff1a<\/p>\n<ul>\n<li>java &#8211; MySQL client vs server time zone &#8211; Stack Overflow<\/li>\n<li>java &#8211; MySQL JDBC Driver 5.1.33 &#8211; Time Zone Issue &#8211; Stack Overflow<\/li>\n<\/ul><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3065151\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yanyueio <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             reply: \u5230\u5e95\u54ea\u91cc\u8fdb\u884c\u8fd9\u6837\u7684\u5904\u7406\u3002<\/p>\n<p>\u56fd\u9645\u5316\u4efb\u52a1\u5904\u7406\u7684\u65f6\u5019\uff0c\u5177\u4f53\u8bf4\u5c31\u662f\u65f6\u95f4\u5904\u7406\u3002\u5f53\u6211\u4eca\u5929\u8fd8\u5728\u4e0a\u6d77\u7528\u4e2d\u6587\u65f6\u533a\uff0c\u7136\u540e\u660e\u5929\u5c31\u5230\u4e86\u897f\u96c5\u56fe\u7528\u7684\u7f8e\u56fd\u897f\u90e8\u65f6\u95f4\u3002\u8981\u5728\u4e24\u4e2a\u9875\u9762\u663e\u793a\u5f53\u5730\u65f6\u95f4(\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u51fa\u6765\u7684)\uff0c\u90a3\u4e48\u8981\u4e48 mysql \u672c\u8eab\u8bbe\u7f6e\u4e86\u7edf\u4e00\u7684\u65f6\u533a(\u901a\u5e38 scm \u4e0d\u4f1a\u7ed9\u4f60\u6743\u9650\u91cd\u542f mysql)\uff0c\u8981\u4e48\u81ea\u5df1\u505a\u597d\u8f6c\u6362(\u901a\u8fc7\u8fde\u63a5\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u8865\u6551\u63aa\u65bd)\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u7684\u65f6\u5019\u548c mysql \u542f\u52a8\u65f6\u8bbe\u7f6e\u7684\u65f6\u533a\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u6700\u597d\u4e86\uff0c\u4e0d\u7528\u5199 connection \u53c2\u6570\uff0c\u5426\u5219\u8fd8\u662f\u8981\u544a\u8bc9 mysql \u6211\u8fd9\u8fb9\u5b58\u8fdb\u53bb\u7684\u65f6\u95f4\u5230\u5e95\u662f\u4ec0\u4e48\u65f6\u533a\u7684(\u5426\u5219\u4e00\u5f8b\u6309\u6570\u636e\u5e93\u7684\u65f6\u533a\u5b58\uff0c\u5426\u5219\u518d\u8bfb\u53d6\u51fa\u6765\u5c31\u53d8\u5473\u4e86)\u3002<\/p>\n<p>hope it helps.<\/p>\n<p>btw: jvm \u542f\u52a8\u65f6\u53ef\u4ee5\u7528 `java.util.TimeZone.setDefault(TimeZone.getTimeZone(&#8220;UTC&#8221;));`\u8bbe\u7f6e\u65f6\u533a\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3065152\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : skai0dev <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ** serverTimezone **:<br \/>Override detection\/mapping of time zone. Used when time zone from server doesn&#8217;t map to Java time zone<\/p>\n<p>from: https:\/\/dev.mysql.com\/doc\/connectors\/en\/connector-j-reference-configuration-properties.html                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3065153\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @skai0dev #2 \u6211\u6709\u70b9\u4e0d\u592a\u7406\u89e3\u201cOverride detection\/mapping of time zone. Used when time zone from server doesn&#8217;t map to Java time zone\u201d\uff0c\u53ef\u4ee5\u5177\u4f53\u89e3\u91ca\u4e00\u4e0b\u5417\uff1f\u8c22\u8c22\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3065154\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yanyueio #1 <br \/>@skai0dev #2 <\/p>\n<p>\u901a\u8fc7 @palfortime \u5728\u201cMySQL \u65f6\u95f4\u201c\u4e0d\u6b63\u786e\u201d\u95ee\u9898 &#8211; V2EX\u201d\u7684\u56de\u7b54 &#8211; https:\/\/www.v2ex.com\/t\/700563#reply15\uff0c\u6211\u660e\u767d\u4e86\u4e3a\u4ec0\u4e48\u201c\u5728 connection URL string \u4e2d\u8bbe\u7f6e\u65f6\u533a\u201d\u4f1a\u5c06\u6240\u8bbe\u7f6e\u65f6\u533a\u7684\u65f6\u95f4\u5b58\u50a8\u5230 MySQL \uff1f\u660e\u767d\u4e86\u5230\u5e95\u662f\u54ea\u91cc\u8fdb\u884c\u8fd9\u6837\u7684\u5904\u7406\u7684\uff1f\u3002<\/p>\n<p>\u5728 https:\/\/github.com\/mysql\/mysql-connector-j\/blob\/79a4336f140499bd22dd07f02b708e163844e3d5\/src\/main\/protocol-impl\/java\/com\/mysql\/cj\/protocol\/a\/NativeProtocol.java#L2228 \u4e2d\uff0c\u4f1a\u83b7\u53d6\u5230 connection URL string \u4e2d\u6240\u8bbe\u7f6e\u7684 serverTimezone\uff0c\u6700\u540e\u4f1a\u8bbe\u7f6e serverSession \u7684 serverTimeZone \u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>JDBC connection U&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/150168"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150168"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/150168\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}