Help us understand the problem. What is going on with this article?

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

設定方法

  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 |
+------------------+------------+
tailak
Software Developer.
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした