我有一个将数据保存到表中的事件:
CREATE DEFINER=`root`@`i2` EVENT `AcrhiveData` ON SCHEDULE EVERY 5
MINUTE STARTS '2017-03-13 10:45:00' ON COMPLETION NOT PRESERVE ENABLE DO
INSERT INTO `archived`(`projectNo`, `staff_id`, `longname`, `username`, `title`, `process`, `creation_time`)
SELECT a.*
FROM
(
(
SELECT p.projectNo,
usr.staff_id,
usr.longname,
usr.username,
p.title,
CONCAT(upr.process, " (", upr.role, ")" ) AS process,
NOW() AS creation_time
FROM project p
INNER JOIN user_project upr
ON p.projectNo = upr.projectNo
INNER JOIN user usr
ON upr.username = usr.username
WHERE EXISTS (SELECT status FROM check_change WHERE status = "1" )
)
) AS a
ORDER BY a.projectNo
它有效,但问题是NOW()
中的时间不正确。如果我将2017-03-29-10:50:00
保存在我的电脑上,则会将其保存为2017-03-29 02:50:00
有什么问题,我该如何解决?
答案 0 :(得分:0)
我认为您应该重置mysql的时区:
mysql> SET GLOBAL time_zone = '+08:00';
SET time_zone = '+08:00';
INSERT INTO `archived`(`projectNo`, `staff_id`, `longname`, `username`, `title`, `process`, `creation_time`)
SELECT a.*
......
答案 1 :(得分:0)
而不是NOW() AS creation_time
我使用了DATE_ADD(UTC_TIMESTAMP(), INTERVAL 8 HOUR) AS creation_time