{"id":150403,"date":"2020-09-02T20:23:22","date_gmt":"2020-09-02T12:23:22","guid":{"rendered":"http:\/\/4563.org\/?p=150403"},"modified":"2020-09-02T20:23:22","modified_gmt":"2020-09-02T12:23:22","slug":"mysql-%e6%97%b6%e9%97%b4%e4%b8%8d%e6%ad%a3%e7%a1%ae%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=150403","title":{"rendered":"MySQL \u65f6\u95f4\u201c\u4e0d\u6b63\u786e\u201d\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  MySQL \u65f6\u95f4\u201c\u4e0d\u6b63\u786e\u201d\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <span><i><\/i> 16<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u51c6\u5907\u5de5\u4f5c\uff08\u6570\u636e\u5e93\uff09<\/h2>\n<pre><code>docker run --rm --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=test -e TZ='Asia\/Shanghai' -p 3306:3306 -d mysql:8  docker exec -it some-mysql mysql -u root -pmy-secret-pw  use test; create table t (dt datetime); <\/code><\/pre>\n<h2>\u771f\u5b9e\u7ed3\u679c &amp; \u671f\u671b\u7ed3\u679c<\/h2>\n<p>\u7a0b\u5e8f\u901a\u8fc7 MyBatis \u6267\u884c<code>insert into t (dt) values (#{now})<\/code>\uff0c\u53d8\u91cf<code>now<\/code>\u662f\u901a\u8fc7<code>Instant.now()<\/code>\u4ea7\u751f\u7684\uff0c\u5176\u503c\u4e3a<code>2020-08-22T11:48:22.150Z<\/code>\uff0c\u8fd9\u662f\u6b63\u786e\u7684\u3002\u4f46\u662f\u4e3a\u4ec0\u4e48\u6570\u636e\u5e93\u5b58\u50a8\u7684\u662f<code>2020-08-22 06:48:22<\/code>\u5462\uff1f\u4e0d\u5e94\u8be5\u662f<code>2020-08-22 19:48:22<\/code>\u5417\uff1f<code>2020-08-22 06:48:22<\/code>\u662f\u600e\u4e48\u6765\u7684\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>15<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3059917\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xupefei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7528\u7684\u955c\u50cf\u6709 tzdata \u5305\u4e48\uff1f<br \/>mysql select now()\u770b\u770b\u7ed3\u679c\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059918\" 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>                                                             `docker exec -it some-mysql mysql -u root -pmy-secret-pw`\uff0c\u7136\u540e\u6267\u884c`select now();`\uff0c\u5176\u7ed3\u679c\u4e3a`2020-08-22 20:19:13`\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059919\" 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>                                                             @xupefei #1 `docker exec -it some-mysql mysql -u root -pmy-secret-pw`\uff0c\u7136\u540e\u6267\u884c`select now();`\uff0c\u5176\u7ed3\u679c\u4e3a`2020-08-22 20:19:13`\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059920\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xupefei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a now()\u63d2\u5230\u8868\u91cc\u5728\u8bfb\u51fa\u6765\uff0c\u5982\u679c\u6ca1\u95ee\u9898\u7684\u8bdd\u5c31\u5f00\u59cb debug mybatis \u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059921\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanbg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker \u5bb9\u5668\u7684\u65f6\u533a\u3001mysql \u7684\u65f6\u533a\u3001jvm \u7684\u65f6\u533a\u3001tomcat \u7684\u65f6\u533a\uff0c\u5b83\u4eec\u90fd\u4e0d\u662f\u4e00\u56de\u4e8b\u3002\u8981\u5168\u7edf\u4e00\u4e3a\u4e1c\u516b\u533a\uff0c\u624d\u80fd\u591f\u8ba9\u65f6\u95f4\u548c\u73b0\u5b9e\u4fdd\u6301\u4e00\u81f4\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059922\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rockyou12 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9996\u5148\u4f60\u6570\u636e\u7c7b\u578b\u662f\u5565\uff1f long \u3001timestamp \u3001datetime \uff1f<br \/>\u7136\u540e\u4f60\u5de5\u5177\u4e0d\u540c\u4e5f\u53ef\u80fd\u9020\u6210\u663e\u793a\u4e0d\u4e00\u6837\uff08\u8d77\u7801\u6211\u4e4b\u524d\u7528 navicat \u548c idea \u770b pg \u7684 timestampz\uff0c\u540c\u4e2a\u65f6\u95f4\u65f6\u533a\u5c31\u662f\u663e\u793a\u4e0d\u4e00\u6837\uff09\uff0c\u4f60 sql \u91cc\u663e\u5f0f\u8f6c\u6210 utc \u65f6\u95f4\u770b\u662f\u4e0d\u662f\u4e00\u81f4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059923\" 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>                                                             @xupefei #4 <br \/>@xuanbg #5 <br \/>@rockyou12 #6 <\/p>\n<p>\u901a\u8fc7\u5728 connection URL string \u4e2d\u663e\u5f0f\u5730\u8bbe\u7f6e\u65f6\u533a\uff08 serverTimezone=Asia\/Shanghai \uff09\u89e3\u51b3\u4e86\uff0c\u539f\u56e0\u662f\u65f6\u533a\u7684\u4e0d\u4e00\u81f4\u5bfc\u81f4\u7684\uff0c\u9ed8\u8ba4\u7684\u65f6\u533a\u5e94\u8be5\u662f UTC\u221205:00 \u3002<\/p>\n<p>Setting the MySQL JDBC Timezone In Spring Boot | Baeldung &#8211; https:\/\/www.baeldung.com\/mysql-jdbc-timezone-spring-boot#param                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059924\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chihiro2014 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65f6\u533a\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059925\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : petelin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6240\u4ee5 mysql \u91cc\u9762\u4e0d\u8981\u7528\u65f6\u95f4 \u7528\u4e00\u4e2a int64 \u4e0d\u9999\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059926\" 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>                                                             @petelin #9 \u5173\u4e8e\u4f7f\u7528\u4ec0\u4e48\u6570\u636e\u7c7b\u578b\u5b58\u50a8\u65f6\u95f4\uff0c\u7f51\u4e0a\u771f\u7684\u4ec0\u4e48\u8bf4\u6cd5\u90fd\u6709\u3002\u4e0b\u9762\u662f\u6211\u627e\u5230\u7684\u4e00\u4e9b\u8d44\u6599\uff0c\u5e0c\u671b\u5bf9\u770b\u5230\u8fd9\u4e2a\u4e3b\u9898\u7684\u4eba\u6709\u6240\u5e2e\u52a9\u3002\u5bf9\u4e8e\u4f7f\u7528 BIGINT \u5b58\u50a8\u65f6\u95f4\uff0c\u6211\u6682\u65f6\u4e0d\u592a\u6e05\u695a\u90a3\u6837\u5b50\u505a\u7684\u5229\u5f0a\uff0c\u53ef\u80fd\u4e4b\u540e\u4f1a\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u770b\u770b\u5b83\u7684\u5229\u5f0a\u5230\u5e95\u662f\u4ec0\u4e48\u3002<\/p>\n<p>integer &#8211; Should I use a big INT or regular INT in MySQL to store a timestamp? &#8211; Stack Overflow &#8211; https:\/\/stackoverflow.com\/questions\/2031228\/should-i-use-a-big-int-or-regular-int-in-mysql-to-store-a-timestamp<\/p>\n<p>mysql &#8211; DATETIME VS INT for storing time? &#8211; Stack Overflow &#8211; https:\/\/stackoverflow.com\/questions\/43705935\/datetime-vs-int-for-storing-time<\/p>\n<p>Should I use the datetime or timestamp data type in MySQL? &#8211; Stack Overflow &#8211; https:\/\/stackoverflow.com\/questions\/409286\/should-i-use-the-datetime-or-timestamp-data-type-in-mysql<\/p>\n<p>Adam D&#8217;Angelo&#8217;s answer to What is the best way to store a timestamp in MySQL? &#8211; Quora &#8211; https:\/\/www.quora.com\/What-is-the-best-way-to-store-a-timestamp-in-MySQL\/answer\/Adam-DAngelo                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059927\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : m1ch3ng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5\uff1aecho &#8220;Asia\/Shanghai&#8221; &gt; \/etc\/timezone                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059928\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palfortime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JasonLaw \u4e0d\u662f\u9ed8\u8ba4\u65f6\u533a\u662f-05:00\uff0c\u662f\u4e2d\u56fd\u7684\u65f6\u533a\u7f29\u5199\u662f CST\uff0c\u7f8e\u56fd Central Standard Timezone \u7f29\u5199\u4e5f\u662f CST\uff0cmysql \u9ed8\u8ba4\u8ba4\u4e3a CST \u662f\u7f8e\u56fd\u90a3\u4e2a\u65f6\u533a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059929\" 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>                                                             @palfortime \u6211\u4e0d\u592a\u660e\u767d\u4f60\u6240\u8bf4\u7684\u201cmysql \u9ed8\u8ba4\u8ba4\u4e3a CST \u662f\u7f8e\u56fd\u90a3\u4e2a\u65f6\u533a\u201d\uff0c\u6211\u5df2\u7ecf\u8bbe\u7f6e\u4e86\u65f6\u533a\u4e3a Asia\/Shanghai \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059930\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palfortime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JasonLaw \u5177\u4f53\u6211\u4e5f\u6ca1\u6709\u6df1\u5165\u7814\u7a76\uff0c\u6211\u731c\u662f\u670d\u52a1\u5668\u8fd4\u56de\u4e86 cst\uff0cmysql connector \u5c31\u6309\u7f8e\u56fd cst \u65f6\u95f4\u6765\u8ba1\u7b97\uff0c\u4f20\u7ed9\u670d\u52a1\u5668\u7684\u65f6\u95f4\u5c31\u662f\u897f\u4e94\u533a\u65f6\u95f4\uff0c\u4e5f\u5c31\u662f\u6211\u56fd\u65f6\u95f4\u51cf\u5341\u4e09\u5c0f\u65f6\u3002<br \/>\u5176\u5b9e\uff0c\u6211\u4e3b\u8981\u60f3\u8868\u8fbe\u4f60\u8bf4\u7684\u9ed8\u8ba4\u65f6\u533a\u662f\u897f\u4e94\u533a\u7684\u8bf4\u6cd5\u662f\u6709\u95ee\u9898\u7684\u3002\u4e00\u822c\u6765\u8bf4\u6709\u9ed8\u8ba4\u65f6\u533a\u4e5f\u5e94\u8be5\u662f GMT \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3059931\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palfortime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8be6\u7ec6\u770b\u4e86\u4e00\u4e0b\uff1a<br \/>1. com.mysql.cj.protocol.a.NativeProtocol \u7684 configureTimezone \u65b9\u6cd5\uff0c\u4f1a\u83b7\u53d6 mysql \u670d\u52a1\u5668\u53d8\u91cf system_time_zone\uff0c\u6211\u7684 mysql \u4e2d\u8fd9\u4e2a\u53d8\u91cf\u662f CST \uff1b<br \/>2. \u63a5\u7740\uff0c\u901a\u8fc7 TimeUtil.getCanonicalTimezone \u8fd9\u4e2a\u65b9\u6cd5\uff0c\u628a CST \u8f6c\u6210\u552f\u4e00\u7684\u65f6\u533a\u8868\u73b0\u683c\u5f0f\uff1b<br \/>3. TimeUtil.getCanonicalTimezone \u6700\u7ec8\u662f\u4ece sun.util.calendar.ZoneInfoFile \u91cc\u83b7\u53d6\u5230 CST \u7684\u6620\u5c04\uff1a{ &#8220;CST&#8221;, &#8220;America\/Chicago&#8221; }\uff1b<\/p>\n<p>\u6240\u4ee5\uff0c\u5ba2\u6237\u7aef\u8bef\u8ba4\u4e3a\u670d\u52a1\u5668\u4f7f\u7528 Chicago \u7684\u65f6\u95f4\uff0c\u4e0a\u9001\u65f6\u95f4\u65f6\u5c31\u4f1a\u8f6c\u6362\u6210\u5bf9\u5e94\u7684 Chicago \u65f6\u95f4\uff0c\u4f46\u670d\u52a1\u5668\u5b9e\u9645\u662f\u4f7f\u7528\u5317\u4eac\u65f6\u95f4\uff0c\u6240\u4ee5\u5bfc\u81f4\u670d\u52a1\u5668\u4fdd\u5b58\u7684\u65f6\u95f4\u4e0e\u5b9e\u9645\u76f8\u5dee\u4e86 13 \u4e2a\u5c0f\u65f6\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u65f6\u95f4\u201c\u4e0d\u6b63\u786e\u201d\u95ee\u9898 \u8cc7&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\/150403"}],"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=150403"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/150403\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150403"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}