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

Markup language - simplified tags

Click here to return to the 123WORDPRESS.COM HTML ...

Example code for using text-align and margin: 0 auto to center in CSS

Use text-align, margin: 0 auto to center in CSS W...

Solve the problem of managing containers with Docker Compose

In Docker's design, a container runs only one...

MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci

Reference: MySQL character set summary utf8mb4 ha...

Ubuntu 20.04 turns on hidden recording noise reduction function (recommended)

Recently, when using kazam in Ubuntu 20.04 for re...

Detailed explanation of the principles of Vue's responsive system

Table of contents The basic principles of Vue'...

How to use Nginx to handle cross-domain Vue development environment

1. Demand The local test domain name is the same ...

CentOS 7.x deployment of master and slave DNS servers

1. Preparation Example: Two machines: 192.168.219...

Detailed explanation of MySQL replication principles and practical applications

This article uses examples to illustrate the prin...

Detailed explanation of HTML document types

Mine is: <!DOCTYPE html> Blog Garden: <!...

How to display JSON data in HTML

background: Sometimes we need to display json dat...