Software Version
Problem DescriptionWhen java saves the current time to MySQL database, the time in MySQL is incorrect Problem Analysis Reason 1: Java database connection uses the UTC time zone (universal time), that is, serverTimezone=UTC url: jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=true Reason 2: The time_zone attribute used by MySQL is +00:00, and Beijing time is 8 hours earlier than UTC time, that is, UTC+08:00 Check MySQL/** * You can view the global time zone settings and session time zone settings * global.time_zone is responsible for the time zone setting when java connects to the database * session.time_zone is responsible for the time zone setting when the Navicat client connects to the database * / mysql> select @@global.time_zone,@@session.time_zone; /** * There is another method * System represents the use of system time zone * CST is a very messy time zone, it includes 4 time zones * / mysql> show variables like '%time_zone%'; // Verify the time zone. This command line can detect whether session.time_zone is configured correctlymysql> select now(); Workaround Step 1: Change the time zone in Java to East 8 // serverTimezone can be set to Beijing time GMT%, Shanghai time Asia/Shanghai or Hongkong time Hongkong url: jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true Step 2: Change the time zone of the MySQL database to East 8 // Method 1: Use command (Advantage: No need to restart MySQL service, Disadvantage: Once MySQL service is restarted, the settings will disappear) mysql> set time_zone = '+8:00'; mysql> set global time_zone = '+8:00'; // Method 2: Modify the my.ini configuration file (Advantage: Permanently save settings, Disadvantage: Need to restart the MySQL service) [mysqld] // Set the default time zone default-time_zone='+8:00' This is the end of this article about the steps to solve the MySQL 8.0 time zone problem. For more relevant MySQL 8.0 time zone content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to create your own Docker image and upload it to Dockerhub
>>: XHTML language default CSS style
Table of contents Basic usage of Promise: 1. Crea...
Table of contents Preface Rationale Procedure 1. ...
During today's lecture, I talked about the di...
This article records the installation and configu...
Table of contents Symbol Data Type The reason why...
1. Create a scheduling task instruction crontab -...
Syntax format: row_number() over(partition by gro...
Steps: 1. Install MySQL database 1. Download the ...
Today is still a case of Watch app design. I love...
This article introduces the sample code of CSS to...
To execute a shell command in Docker, you need to...
In order to extend the disk life for storing audi...
radio-and-checkbox Pure CSS to achieve radio and ...
Table of contents Docker container data volume Us...
Introduction to Nginx Nginx ("engine x"...