LoginSignup
4
1

More than 5 years have passed since last update.

MySQLのtimezoneをUTCに出来ないときに試すメモ

Last updated at Posted at 2017-02-16

mac。MySQL は Oracle 公式パッケージでインストールした 5.7。

そのままだと JST で時刻が扱われたので、
↓ 下記を作成する。

my.cnf
$ cat /etc/my.cnf 
[mysqld_safe]
timezone = UTC
default-time-zone = UTC

これで、システム環境設定からmysqldをstop->startしたが、UTCにならなかった。

mysql>  show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | JST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

mysql> select NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2017-02-16 10:33:06 |  
+---------------------+
1 row in set (0.00 sec)

↑ JSTの現在時刻が返ってきている

そこで。

timezone情報をmysqlデータベースに入れる。

$ sudo /usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql>  show variables like '%time_zone%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| system_time_zone | JST   |
| time_zone        | UTC   |
+------------------+-------+
2 rows in set (0.02 sec)

mysql> select NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2017-02-16 01:34:20 |
+---------------------+
1 row in set (0.00 sec)

↑ UTCで返ってきてくれた :raised_hands:

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1