mysql数据库监控规定的表中每五分钟内没有新数据产生则报警提示,最好把这个提示信息放到一个txt的文件里
存放各个表的表名:total
字段:id,tablenames(表的名字),time_colum(每个表对应的时间段的名字),fix_time(规定的时间比如五分钟)
我自己写了一个存储函数但是发现不是很好用,1.请大家重新帮忙写一个别的方法;2或者是提示我一下我这个的报错怎么改正比较好;
存储函数如下:
delimiter &&
create function alarm_info()
returns varchar(100) reads sql data
begin
declare counts int(11);
declare n int(11);
declare fixs int(11);
declare times varchar(20);
declare diff int(11);
declare names varchar(20);
declare result varchar(100);
set n=1;
select count(*) into counts from total;
while counts>=n do
select tablenames,time_colum,fix_time into names,times,fixs from total where id=n;
set diff=round(time_to_sec(timediff(sysdate(),(select times from names order by id desc limit 1)))/60);
if(diff>fix_time) then set result=names;
return result;
end if;
set n=n+1;
end while;
end &&
delimiter;
调用时候报错:mysql> select alarm_info();
ERROR 1146 (42S02): Table 'fenda.names' doesn't exist
[解决办法]
set diff=round(time_to_sec(timediff(sysdate(),(select times from names order by id desc limit 1)))/60);
这种语句 from names,只会是从名叫names 表中取。MYSQL怎么知道 names是实际的表名还是什么?
建议你还是简单点,直接在操作系统监视MYSQL的BINLOG文件本身的更新时间比较容易实现。