I am having an issue about the time displayed on a table.
In mariadb, I created a table that has id, name ,gender, created_at and updated_at.
The table looks like this
+----+--------+--------+------+---------------------+---------------------+
| 1 | Taro | m | 20 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 2 | john | m | 18 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 3 | paul | m | 20 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 4 | alice | f | 15 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 5 | dabid | m | 17 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 6 | jasmin | f | 17 | 2021-08-16 17:52:23 | 2021-08-16 17:52:23 |
| 7 | jiro | m | 30 | 2021-08-16 09:22:53 | 2021-08-16 09:22:53 |
+----+--------+--------+------+---------------------+---------------------+
The last two columns created_at and updated_at were created after adding the first six rows.
I added the seventh row at last; however, it somehow says it created first. I added it with ruby module 'ActiveRecord'. A source code looks like this.
require 'active_record'
ActiveRecord::Base.establish_connection(
adapter: "mysql2",
host: "localhost",
username: "admin",
password: "-----",
database: "training",
charset: "utf8mb4",
encoding: "utf8mb4",
)
class User < ActiveRecord::Base
self.table_name = 'users'
end
User.create(name: "jiro", gender: "m", age:"30")
As I live in Tokyo, I assumed that it is happening due to timezone setting. So I typed the following command to see timezone setting on Mariadb.
MariaDB [(none)]> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | JST |
| time_zone | SYSTEM |
+------------------+--------+
I also checked what timezone a system uses with this command and it returns this...
$ date
Tue Aug 17 13:20:42 JST 2021
I want created_at and updated_at to be jst. How do I fix this issue?
Environment
Ubuntu 18.04
WSL1
MariaDB 10.6