задание для удаления строк, более старых, чем 3 месяца в mysql базе данных

cit_work= element.find('citedWork').tag
cit_work= element.find('citedWork').text

В этих случаях, если вы ожидаете, что 'citedWork' может отсутствовать, вы можете проверить, не является ли возвращаемое значение find не None, прежде чем пытаться получить доступ к любому из его атрибутов. [114 ]

cit_work_elem = element.find('citedWork')
if cit_work_elem:
    cit_work = cit_work_elem.text
15
задан 1 May 2009 в 21:45
поделиться

4 ответа

Do you store the date an item is created in a field?

If so,

DELETE FROM myTable WHERE dateEntered < DATE_SUB(NOW(), INTERVAL 3 MONTH);

should work...

You could run it in a scheduled task/cron job...

71
ответ дан 30 November 2019 в 23:51
поделиться

A simple way would be to scheduled a job that runs every night that calls a stored procedure to delete all rows older than three months. Depending on your O/S it should be easy to do. Do it each night and the amount of deleted data won't be as much as doing it once a month or so.

I have also in the past, had code in my SP that inserted data to do the deletes of unneeded data at that time, so basically every time a row is inserted, right after the insert in ran a 'cleanup' proc that did a bit of maintenance. This wouldn't be my first choice, but its doable if the number of inserts is low, and the deletes can be done fast (you don't want to slow the user down). Nice side-effect of this is the data is always clean (i.e. all data is always <= 3 months old), but not sure if that matters in your app.

You should also consider archiving the rows to another table instead in addition to deleting them, if there is any chance you might want the data someday for another purpose. I always do this, and you'd be surprised what a hero you can look like when some manager who doesn't even know you are saving the data, suddenly has an urgent need for it....and you can deliver for them.

2
ответ дан 30 November 2019 в 23:51
поделиться

Перефразируя ваш вопрос: «У меня есть код, который не зависит от клиента, который я хочу запустить в базе данных несколько раз, и мне не нужно видеть вывод», затем Ответ таков: «Запишите сохраненный процесс и регулярно вызывайте его у любого клиента».

-1
ответ дан 30 November 2019 в 23:51
поделиться

MySQL 5.1 поддерживает события . Я на самом деле не использовал их сам, поэтому я не буду ручаться за них. Однако, если все, что вы хотите сделать, это запускать оператор DELETE на регулярной основе, я думаю, что он будет работать достаточно хорошо.

4
ответ дан 30 November 2019 в 23:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: