Score:0

Something is wrong with timezone on mariadb

br flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.