创建表 user
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '名字',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
表结构如下
然后创建触发器使用存储过程定时清除记录
CREATE EVENT `delete_table_trigger`
ON SCHEDULE EVERY 1 SECOND STARTS '2000-01-01 00:00:00'
ON COMPLETION NOT PRESERVE
ENABLE
DO
delete from user where (select num from (select count(id) as num from user as tmp) as t)>100;
创建完毕后,用数据库管理工具phpmyadmin看一下这个数据库的事件
然后尝试往里面插入数据
插入100条,
再插入一条 就会触发触发器进行清空记录了,
达到了当记录大于100的时候自动清空数据