1. 連接登錄MySQL后,先查看MySQL是否開啟了事件功能:
命令:show variables like '%sc%';
發(fā)現(xiàn)event_sheduler是OFF關(guān)閉的;
2. 打開event_scheuler:
臨時開啟(mysql服務(wù)重啟后之后失效)
SET GLOBAL event_scheduler = ON; SET GLOBAL event_scheduler = 1; — 0代表關(guān)閉
永久開啟
在my.cnf中的[mysqld]部分添加如下內(nèi)容,然后重啟mysql(mysql重啟命令:service mysqld restart)
3. 創(chuàng)建事件,這里舉例每5秒鐘定時刪除wififlows表中過期2分鐘的數(shù)據(jù):
create event e_delete_wififlows on schedule every 5 second do delete from wififlows where timestamp (CURRENT_TIMESTAMP() + INTERVAL -2 MINUTE);
如果事先存在這個事件可以使用如下命令進行刪除:
drop event if exists e_delete_wififlows;
然后使用show events;查看存在的事件
4. 開啟事件:
alter event e_del_wififlows on completion preserve enable;
5. 關(guān)閉事件:
alter event e_del_wififlowa on completion preserve disable;
以上這篇mysql定時刪除過期數(shù)據(jù)記錄的簡單方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- MySQL 快速刪除大量數(shù)據(jù)(千萬級別)的幾種實踐方案詳解
- MySQL 處理重復(fù)數(shù)據(jù)的方法(防止、刪除)
- MySQL對數(shù)據(jù)庫操作(創(chuàng)建、選擇、刪除)
- MySQL使用mysqldump+binlog完整恢復(fù)被刪除的數(shù)據(jù)庫原理解析
- mysql數(shù)據(jù)庫常見基本操作實例分析【創(chuàng)建、查看、修改及刪除數(shù)據(jù)庫】
- Linux實現(xiàn)定時備份MySQL數(shù)據(jù)庫并刪除30天前的備份文件
- linux定時備份MySQL數(shù)據(jù)庫并刪除以前的備份文件(推薦)
- MySQL數(shù)據(jù)誤刪除的快速解決方法(MySQL閃回工具)
- Mysql的Binlog數(shù)據(jù)恢復(fù):不小心刪除數(shù)據(jù)庫詳解
- MySQL實現(xiàn)快速刪除所有表而不刪除數(shù)據(jù)庫的方法
- MySQL刪除數(shù)據(jù)庫的兩種方法
- MySQL刪除數(shù)據(jù),表文件大小依然沒變的原因