1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MySQLのタイムゾーンを日本時間にする(Ubuntu18.04)

Posted at

##勘違いしていたこと
MySQLのタイムゾーンはデフォルトでホストマシンのタイムゾーンを参照している!
❎my.cnfを編集する
🔴Ubuntuのタイムゾーンを変更する

#ホストマシン(Ubuntu)のタイムゾーンを変更

$> date
Tue May 11 07:43:16 UTC 2021

日時を確認
UTCからJSTに変える

$> timedatectl set-timezone Asia/Tokyo
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ===
Authentication is required to set the system timezone.
Authenticating as: vagrant,,, (vagrant)
Password:

パスワードを入力
==== AUTHENTICATION COMPLETE ===
と出たら成功

$> date
Tue May 11 16:44:02 JST 2021

JSTになってることを確認

##MySQLを確認
MySQLに接続し確認

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

あれ?変わってない。。。
MySQLを再起動

mysql> exit
Bye
$> systemctl restart mysql
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Authenticating as: vagrant,,, (vagrant)
Password: 
==== AUTHENTICATION COMPLETE ===
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | JST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

行けた!

MySQL再起動することをお忘れなく〜

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?