LoginSignup
107
101

More than 3 years have passed since last update.

MySQLでタイムゾーンを設定する

Last updated at Posted at 2014-12-09

設定方法

  1. タイムゾーンデータのインポート

    タイムゾーンデータのインポートを行い、MySQLのタイムゾーンテーブルを初期化します。

    参考)https://dev.mysql.com/doc/refman/5.6/ja/time-zone-support.html

    • Linuxの場合

      $ /usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo > ~/timezone.sql
      $ mysql -u root -p -Dmysql < ~/timezone.sql
      
    • Windowsの場合
      タイムゾーンデータは、MySQLのサイトよりPOSIX standard版のファイルをダウンロードします。
      https://dev.mysql.com/downloads/timezones.html

      $ mysql -u root -p -Dmysql < /your/path/timezone_posix.sql  
      
  2. my.cnfを変更します。

    /etc/my.cnf
    [mysqld]
    default-time-zone = 'Asia/Tokyo'
    
  3. MySQLの再起動
    MySQLを再起動すると設定が反映されます。
    タイムゾーンデータをインポートしていない場合、my.cnfで指定したTimeZoneが存在しないときは起動エラーになります。

設定の確認

mysql> show variables like '%time_zone%';

+------------------+------------+
| Variable_name    | Value      |
+------------------+------------+
| system_time_zone | JST        |
| time_zone        | Asia/Tokyo |
+------------------+------------+
107
101
1

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
107
101