{"id":293,"date":"2023-02-24T21:58:02","date_gmt":"2023-02-24T13:58:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=293"},"modified":"2023-04-30T15:11:11","modified_gmt":"2023-04-30T07:11:11","slug":"summary-of-methods-for-modifying-time-zones-in-mysql","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/summary-of-methods-for-modifying-time-zones-in-mysql\/","title":{"rendered":"MySQL\u4fee\u6539\u65f6\u533a\u7684\u65b9\u6cd5\u5c0f\u7ed3"},"content":{"rendered":"<p>\u4e3b\u8981\u4ecb\u7ecdMySQL\u4fee\u6539\u65f6\u533a\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u547d\u4ee4\u884c\u6a21\u5f0f\u3001\u914d\u7f6e\u6587\u4ef6\u65b9\u5f0f\u53ca\u4ee3\u7801\u65b9\u5f0f<\/p>\n<h2>\u901a\u8fc7mysql\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u52a8\u6001\u4fee\u6539<\/h2>\n<h3>\u67e5\u770bmysql\u5f53\u524d\u65f6\u95f4\uff0c\u5f53\u524d\u65f6\u533a<\/h3>\n<p><!-- more --><\/p>\n<pre><code>> select curtime();  #\u6216select now()\u4e5f\u53ef\u4ee5\n+-----------+\n| curtime() |\n+-----------+\n| 15:18:10 |\n+-----------+\n> show variables like &quot;%time_zone%&quot;;\n+------------------+--------+\n| Variable_name  | Value |\n+------------------+--------+\n| system_time_zone | CST  |\n| time_zone    | SYSTEM |\n+------------------+--------+\nrows in set (0.00 sec)<\/code><\/pre>\n<p><code>time_zone<\/code>\u8bf4\u660emysql\u4f7f\u7528system\u7684\u65f6\u533a\uff0c<code>system_time_zone<\/code>\u8bf4\u660esystem\u4f7f\u7528CST\u65f6\u533a<\/p>\n<h3>\u4fee\u6539\u65f6\u533a<\/h3>\n<pre><code>> set global time_zone = &#039;+8:00&#039;; #\u4fee\u6539mysql\u5168\u5c40\u65f6\u533a\u4e3a\u5317\u4eac\u65f6\u95f4\uff0c\u5373\u6211\u4eec\u6240\u5728\u7684\u4e1c8\u533a\n> set time_zone = &#039;+8:00&#039;; #\u4fee\u6539\u5f53\u524d\u4f1a\u8bdd\u65f6\u533a\n> flush privileges; #\u7acb\u5373\u751f\u6548<\/code><\/pre>\n<h2>\u901a\u8fc7\u4fee\u6539my.cnf\u914d\u7f6e\u6587\u4ef6\u6765\u4fee\u6539\u65f6\u533a<\/h2>\n<pre><code># vim \/etc\/my.cnf #\u5728[mysqld]\u533a\u57df\u4e2d\u52a0\u4e0a\ndefault-time_zone = &#039;+8:00&#039;\n\n# \/etc\/init.d\/mysqld restart #\u91cd\u542fmysql\u4f7f\u65b0\u65f6\u533a\u751f\u6548<\/code><\/pre>\n<h2>\u5e94\u7528\u7a0b\u5e8f\u8bbe\u7f6e<\/h2>\n<p>\u5982\u679c\u4e0d\u65b9\u4fbf\u91cd\u542fmysql\uff0c\u53c8\u60f3\u4e34\u65f6\u89e3\u51b3\u65f6\u533a\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7php\u6216\u5176\u4ed6\u8bed\u8a00\u5728\u521d\u59cb\u5316mysql\u65f6\u521d\u59cb\u5316mysql\u65f6\u533a<\/p>\n<p>\u8fd9\u91cc\uff0c\u4ee5php\u4e3a\u4f8b\uff0c\u5728<code>mysql_connect()<\/code>\u4e0b\u4f7f\u7528:<\/p>\n<pre><code>mysql_query(&quot;SET time_zone = &#039;+8:00&#039;&quot;)<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5728\u4fdd\u8bc1\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u6539\u53d8\u65f6\u533a\u3002\u4f46\u662fmysql\u7684\u67d0\u4e9b\u7cfb\u7edf\u51fd\u6570\u8fd8\u662f\u4e0d\u80fd\u7528\u5982\uff1a<code>now()<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u8981\u4ecb\u7ecdMySQL\u4fee\u6539\u65f6\u533a\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u547d\u4ee4\u884c\u6a21\u5f0f\u3001\u914d\u7f6e\u6587\u4ef6\u65b9\u5f0f\u53ca\u4ee3\u7801\u65b9\u5f0f \u901a\u8fc7mysql\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u52a8\u6001\u4fee\u6539  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}