CENTOS7 + mysql5.7 Modify select Now (); Problem with time display error

Source: Internet
Author: User
Tags cst time local time

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.