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

时间:2022-09-25 20:07:20

i need to do delayed mysql insert into my database based on the time choosen.

我需要根据选择的时间将延迟的mysql插入到我的数据库中。

Example: Timestamp choosen = "2013-04-03 10:12:00"

示例:Timestamp choosen =“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.

所以我希望我的插入查询在此(“2013-04-03 10:12:00”)特定时间执行。

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

$ 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界面接受用户的这个时间戳值。

and yes, i dont want to do cron jobs

是的,我不想做cron工作

2 个解决方案

#1


0  

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.

您需要为每分钟设置一个cron作业,其中查询正在查找插入查询的任何匹配时间戳。

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作业对于DB健康状况并不是更好,您应该再次考虑时间间隔以获得更好的性能。

#2


0  

You could insert data into additional table, then use MySQL events to copy records into target table at exact time. For example -

您可以将数据插入到附加表中,然后使用MySQL事件在准确的时间将记录复制到目标表中。例如 -

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.

使用事件调度程序。

#1


0  

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.

您需要为每分钟设置一个cron作业,其中查询正在查找插入查询的任何匹配时间戳。

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作业对于DB健康状况并不是更好,您应该再次考虑时间间隔以获得更好的性能。

#2


0  

You could insert data into additional table, then use MySQL events to copy records into target table at exact time. For example -

您可以将数据插入到附加表中,然后使用MySQL事件在准确的时间将记录复制到目标表中。例如 -

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.

使用事件调度程序。