1、建立存储过程
BEGIN
#Routine body goes here...
declare ids INT;
declare stop int default 0;
declare cur cursor for( SELECT id FROM test s WHERE cid = 125 AND statu=1);
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop = null;
OPEN cur;
FETCH cur INTO ids;
WHILE ( stop is not null) DO
UPDATE test set votes = votes + FLOOR(5+RAND()*5) where id=ids;
FETCH cur INTO ids;
END WHILE;
CLOSE cur;
END
2、建立定时事件