How to view and modify the time zone in MySQL

How to view and modify the time zone in MySQL

Today I found that a program inserted an incorrect time, and the field was configured with the default value CURRENT_TIMESTAMP. I initially determined that it was a problem with the database time zone setting.

Check time zone

Log in to the database to view the time zone configuration:

mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | EDT |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
  • system_time_zone indicates that the time zone used by the system is EDT, which is Eastern Daylight Saving Time (-4h) in North America.
  • time_zone indicates that MySQL uses the system's time zone. That is, if no time zone information is set when connecting, this time zone configuration will be used.

Change time zone

To change the time zone:

# Only change the time zone of the current session and stop the session from being invalidated set time_zone = '+8:00';

# Modify the global time zone configuration set global time_zone = '+8:00';
flush privileges;

Of course, you can also modify the configuration file (my.cnf) to achieve the configuration, but you need to restart the service.

# vim /etc/my.cnf ##Add default-time_zone = '+8:00' in the [mysqld] area
# /etc/init.d/mysqld restart ##Restart mysql to make the new time zone take effect

By the way, unlike China, the United States has 4 time zones...

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • mysql solves time zone related problems
  • Detailed explanation of mysql time zone problem in Java
  • Summary of methods for modifying MySQL time zone
  • How to distinguish uppercase and lowercase letters in strings when querying MySQL
  • mysql time zone problem
  • Steps to solve the MySQL 8.0 time zone problem

<<:  Detailed explanation of setting static ip network card for CentOS 8 VMware virtual machine to access the Internet

>>:  Mini Programs use Mini Program Cloud to implement WeChat payment functions

Recommend

How to use Docker containers to implement proxy forwarding and data backup

Preface When we deploy applications to servers as...

MySQL restores data through binlog

Table of contents mysql log files binlog Binlog l...

Vue implements a simple magnifying glass effect

This article example shares the specific code of ...

CSS and CSS3 flexible box model to achieve element width (height) adaptation

1. CSS realizes fixed width on the left and adapt...

Detailed steps for installing MinIO on Docker

Table of contents 1. Check whether the docker env...

JavaScript implements H5 gold coin function (example code)

Today I made a Spring Festival gold coin red enve...

How to upgrade all Python libraries in Ubuntu 18.04 at once

What is pip pip is a Python package management to...

Summary on Positioning in CSS

There are four types of positioning in CSS, which...

Summary of all HTML interview questions

1. The role of doctype, the difference between st...

Detailed explanation of three solutions to the website footer sinking effect

Background Many website designs generally consist...

Solution to the problem of repeated pop-up of Element's Message pop-up window

Table of contents 1. Use 2. Solve the problem of ...