Home > Database > Mysql Tutorial > body text

MySQL触发器的创设

WBOY
Release: 2016-06-07 16:26:44
Original
1205 people have browsed it

MySQL触发器的创建 项目要求将自控数据读取到关系型数据库中用于门户系统的数据显示,由于数据量较大需要定时清除表中数据,因此需要借助MySQL的事件调度调度器。 1.查看事件调度器是否已经开启; show variables like '%sche%'; ?2.如事件尚未开启,则执行如

MySQL触发器的创建

项目要求将自控数据读取到关系型数据库中用于门户系统的数据显示,由于数据量较大需要定时清除表中数据,因此需要借助MySQL的事件调度调度器。

1.查看事件调度器是否已经开启;

show variables like '%sche%';
Copy after login

?2.如事件尚未开启,则执行如下命令。

set global event_scheduler =1;
Copy after login

?3.创建删除事件,每隔一个小时清除一次数据。

create event if not exists e_delete 
on schedule every 1 hour 
on completion preserve 
do 
delete from shcema.test; 
Copy after login

?

查看调度器状态:

mysql>show events \G;
Copy after login

?说明:但注意,当你重启MySQL服务时,事件调度器就会自动关闭,以上方法只是暂时开启,若想永久开启,就要修改MySQL的配置文件 (该文件,Linux的在/usr目录my..cnf下,Windows在其安装目录my-default.ini),打开配置文件,在[mysqld]增加以下配置

event_scheduler=ON
Copy after login

保存后,重启MySQL服务:service mysql restart,? 那事件调度器就会永久开启了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!