D
D
Dmitry Cherednichenko2014-10-25 13:33:35
PHP
Dmitry Cherednichenko, 2014-10-25 13:33:35

How to set scheduled tasks?

Hello! Such a task: it is necessary that records from the TABLE table be deleted every 30 days in the mysql BUILD database. How to implement it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Petrikov, 2014-10-25
@likeapimp

It is possible through the system cron, it is possible through the scheduler (events of mysql itself), through the cron banality and information in the Google Sea, through the scheduler - more interesting:
By default, in most versions of MySQL, the scheduler is disabled. To enable it, add event_scheduler = 1; to the MySQL configuration file. To avoid restarting MySQL, the following command should be executed: SET GLOBAL event_scheduler = ON;
Then we create an event like:

DELIMITER $$
 
CREATE EVENT IF NOT EXISTS `e_part_manage`
       ON SCHEDULE EVERY 30 DAY
       STARTS '2014-10-10 04:00:00'
       ON COMPLETION PRESERVE
       ENABLE
       COMMENT 'Управление удалением записей'
       DO BEGIN
Тут можно как напрямую вставить команду удаления, так и использовать процедуру
       END$$
 
DELIMITER ;

Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question