MySQL 存储过程 定时任务

时间:2021-07-14 06:23:45
drop procedure if exists move_track_data;
delimiter //
create procedure move_track_data()
begin
declare i int default 0;
start transaction;
set i = 1;
case
when i = 1 then
select 'is 1';
when i = 2 then
select 'is 2';
else
select 'is 3';
end case;
commit;
end;
// call move_track_data();
delimiter ;
select * from score_driving_track where trackid in( select trackid from score_driving_track where trackid % 10 = 1); insert into score_driving_track_0 select * from score_driving_track where trackid in( select trackid from score_driving_track where trackid % 10 =0); ####################################################################################################3 set time_zone = '+8:00';
set GLOBAL event_scheduler = 1;
use test;
drop event if exists upload_to_sdmp;
DELIMITER //
create event upload_to_sdmp
on schedule every 1 week starts timestamp '2015-10-12 02:00:00'
do call move_score_driving_track_data(); drop procedure if exists move_score_driving_track_data;
delimiter //
create procedure move_score_driving_track_data()
begin
declare i int default 0;
declare t_error integer default 0;
declare continue handler for sqlexception set t_error = 1;
start transaction;
set i = 0;
while i < 10 do
set @sqlTrackids = concat('select group_concat(distinct trackid) into @trackids from score_driving_track where trackid % 10 = ', i);
select @sqlTrackids;
prepare sqlTrackidsNormal from @sqlTrackids;
execute sqlTrackidsNormal;
select @trackids; set @sqlInsert = concat('insert into score_driving_track_', i, ' select * from score_driving_track where find_in_set(trackid, ''', @trackids, ''')');
select @sqlInsert;
prepare sqlInsertNormal from @sqlInsert;
execute sqlInsertNormal; set @sqlDelete = concat('delete from score_driving_track', ' where find_in_set(trackid ,''', @trackids, ''')');
select @sqlDelete;
prepare sqlDeleteNormal from @sqlDelete;
#execute sqlDeleteNormal; set i = i + 1;
end while;
if t_error = 1 then
rollback;
else
commit;
end if;
end;
//
call move_score_driving_track_data();
SELECT @@global.sort_buffer_size; select * from score_driving_track where trackid >= 2270;
select * from score_driving_track_0;
select * from score_driving_track_1;
select * from score_driving_track_2;
select * from score_driving_track_3;
select * from score_driving_track_4;
select * from score_driving_track_5;
select * from score_driving_track_6;
select * from score_driving_track_7;
select * from score_driving_track_8;
select * from score_driving_track_9; delete from score_driving_track_0;
delete from score_driving_track_1;
delete from score_driving_track_2;
delete from score_driving_track_3;
delete from score_driving_track_4;
delete from score_driving_track_5;
delete from score_driving_track_6;
delete from score_driving_track_7;
delete from score_driving_track_8;
delete from score_driving_track_9; SET GLOBAL group_concat_max_len=1024000; show variables like "group_concat_max_len";
##################################################################################### call move_score_driving_track_data();
SELECT @@global.sort_buffer_size; SET GLOBAL group_concat_max_len=1024000; show variables like "group_concat_max_len"; select group_concat(distinct trackid) from score_driving_track where trackid % 10 = 0;
SELECT @@global.group_concat_max_len;
show warnings;
#[mysqld]
#explicit_defaults_for_timestamp=true
#group_concat_max_len=102400
select distinct trackid from score_driving_track where trackid % 10 = 0; select group_concat(distinct trackid) from score_driving_track where trackid % 10 = 0 and trackid < 50; delimiter ;
select concat('score_driving_track_', 1); select * from score_driving_track_0; delete from score_driving_track_0; ##############################################################################
set time_zone = '+8:00';
set GLOBAL event_scheduler = 1;
use test;
drop event if exists upload_to_sdmp;
DELIMITER //
create event upload_to_sdmp
on schedule every 1 second #starts timestamp '2014-07-30 10:00:00'
do
begin
insert into b values(3,'');
insert into b values(2,'');
end
//
DELIMITER ; select * from b; select group_concat(trackid) into @temp from score_driving_track where trackid < 100;
select @temp;
select * from score_driving_track where find_in_set(trackid, @temp);
select REPLACE(@temp,'''''''',''); select CHAR_LENGTH(@temp)-CHAR_LENGTH(REPLACE(@temp,'','')) + 1; select * from score_driving_track where trackid in (select group_concat(trackid) from score_driving_track where trackid < 50); select * from score_driving_track where find_in_set(trackid, (select group_concat(distinct trackid) from score_driving_track where trackid < 50)); select * from users;