ATOTCLIC Linux Eventos Mysql

Eventos Mysql

SET GLOBAL event_scheduler = ON;

CREATE EVENT mievento
ON SCHEDULE EVERY 1 HOUR
STARTS CURRENT_TIMESTAMP
DO
DELETE FROM tblreseteopass WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 2 DAY);
/* Affected rows: 0  Filas encontradas: 0  Advertencias: 0  Duración para 1 query: 0,047 sec. */


ALTER EVENT mievento
ON SCHEDULE EVERY 10 MINUTE
STARTS CURRENT_TIMESTAMP
DO
DELETE FROM tblreseteopass WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 5 MINUTE);
/* Affected rows: 0  Filas encontradas: 0  Advertencias: 0  Duración para 1 query: 0,000 sec. */


MariaDB [test]> SET GLOBAL event_scheduler = ON;
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> show create event mievento1 \G
*************************** 1. row ***************************
Event: mievento1
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE  /* DEFINER=`root`@`localhost` */ EVENT `mievento` ON SCHEDULE EVERY 10 MINUTE STARTS '2016-09-17 11:06:09' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM tbl_test WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 5 MINUTE)
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)


DROP EVENT mievento;

O podemos detener el event_scheduler con el siguiente comando:

SET GLOBAL event_scheduler = OFF;

Related Post

Mysql consultasMysql consultas

SELECT table_name AS "Tables", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES ORDER BY (data_length + index_length) DESC; SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table',