Yesterday, developers suggested that when using the MySQL database, the database time to see the problem, and local time is inconsistent;
One: View issues
1. In the database: view time;
Mysql> mysql> Select Now ();
+---------------------+
| Now () |
+---------------------+
| 2017-06-15 15:10:15 |
+---------------------+
1 row in Set (0.00 sec)
2. On the Linux server: View time:
[[Email protected] ~]# Date
Wed June 15:10:11 EDT 2017
Note:
EDT: US Eastern Daylight Time, Boston, New York, Washington Columbia, Dist. Of, all in this timezone, with the 12-hour jet lag, 12 hours late
CST: can refer to the following two kinds:
1. Central US Standard Time (West six, -6:00), China is East Eight, Beijing time is 14 hours earlier than Central American Standard time. 3:45 PM CST is 1:45 Beijing time.
2. Australia Standard Time (+10:30), China is the East Eight district (at), Beijing time is 2.5 hours later than the Australian Standard Time. 3:45 pm CST is Beijing time 5:45 pm.
Second: Now to change to the time zone CST in Beijing, and the time in the database should also be consistent with the server time display, modified as follows:
1.
Change the EDT time zone to the ECT time zone:
Before modification:
[[Email protected] ~]# Date
Wed June 15:11:06 EDT 2017
Modify:
[Email protected] ~]# Mv/etc/localtime/etc/localtime.bak
[Email protected] ~]# ln-s/usr/share/zoneinfo/asia/shanghai/etc/localtime
After modification:
[[Email protected] ~]# Date
Thu June 15:16:09 CST 2017
3.
There are two Linux clocks, one is the hardware clock, that is, the BIOS time, which is the time we see in the CMOS setup, and the other is the system clock, which is the kernel time of the Linux system.
The two are often inconsistent;
Solve:
# clock--SYSTOHC # Synchronize system time to hardware time
# clcok-w # force system time to be written to CMOS
To see the effect:
Server:
[[Email protected] ~]# Date
Thu June 15:23:26 CST 2017
MySQL database:
Mysql> Select Date_format (now (), "%y-%m-%d%h:%i:%s");
+----------------------------------------+
| Date_format (now (), "%y-%m-%d%h:%i:%s") |
+----------------------------------------+
| 2017-06-15 15:23:29 |
+----------------------------------------+
1 row in Set (0.00 sec)
The MySQL database is consistent with the Linux server time and is the CST time zone. Mission Accomplished!
This article from "to Guanshuxian" blog, declined reprint!
CENTOS7 + mysql5.7 Modify select Now (); Problem with time display error