The mysql time deployed under the cloud server Docker is 8 hours less than the actual time Solution

 Deployed on the cloud server, the default current time of MySQL is 8 hours less than the current actual time, but the local data data is normal, so the time zone of mysql that may be located in docker is wrong

 MySQL database 

Field: create_time Type: timestamp Default: CURRENT_TIMESTAMP

Corresponding entity class    

private LocalDateTime createTime;

1. View process/container:

docker ps

2. Enter the MySQL container:

docker exec -it f4a2d6bf1063 /bin/bash

3. Enter the command: 

date

Check the time, you will find that it is 8 hours less than the current time

 

4. Enter exit. Exit the MySQL container and return to centos, replace the time zone file with the container file

docker cp /usr/share/zoneinfo/Asia/Shanghai mysql:/usr/share/zoneinfo/Asia
 
docker exec -it cf-mysql bash
 
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

5. Restart

docker stop mysql
 
docker start mysql

6. Use local Navicat to view MySQL current time

select now();

Guess you like

Origin blog.csdn.net/ywp2021/article/details/127795168