简体   繁体   English

基于时间戳的MySql插入查询(延迟插入)

[英]MySql Insert Query based on Timestamp (delayed insert)

i need to do delayed mysql insert into my database based on the time choosen. 我需要根据选择的时间mysql insert delayed mysql insert我的数据库中。

Example: Timestamp choosen = "2013-04-03 10:12:00" 示例:选择的Timestamp = "2013-04-03 10:12:00"

so i want my insert query to get executed at this ("2013-04-03 10:12:00") particular time. 所以我希望我的insert query在此特定时间("2013-04-03 10:12:00")执行。

$qry = mysql_query("INSERT INTO table (field) value ($value)");

i am having a mysql innoDB database. 我有一个mysql innoDB数据库。

and i will be accepting this timestamp value from user from a HTML+PHP interface. 并且我将从HTML+PHP界面接受用户的timestamp值。

and yes, i dont want to do cron jobs 是的,我dont wantcron jobs

No option without cron job... 没有cron工作就没有选择...

You need a cron job setup for every minute , in which the query is looking for any matching timestamp for the insert query. 您需要every minute进行every minute cron job设置,查询将在其中查找插入查询的任何匹配时间戳。

But for every minute cron job is not better for DB health if you have more and more data to insert, you should think again about the time interval for better performance. 但是,如果要插入的数据越来越多,那么每分钟的cron job都不会对数据库健康有所帮助,您应该重新考虑时间间隔以提高性能。

You could insert data into additional table, then use MySQL events to copy records into target table at exact time. 您可以将数据插入到其他表中,然后使用MySQL事件在准确的时间将记录复制到目标表中。 For example - 例如 -

CREATE EVENT event1
  ON SCHEDULE AT '2013-04-03 20:00:00'
  DO 
BEGIN
  INSERT INTO <table> SELECT * FROM <temp table>;
  TRUNCATE TABLE <temp table>;
END

Using the Event Scheduler . 使用事件计划程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM