MySQL event automatic kill runtime time-out SQL

Source: Internet
Author: User
Tags prepare

Delimiter $
Create Event My_long_running_trx_monitor
On schedule every 1 minute
Starts ' 2015-09-15 11:00:00 '
On completion preserve enable do
Begin
DECLARE v_sql varchar (500);
Declare No_more_long_running_trx integer default 0;
DECLARE C_tid cursor FOR
Select Concat (' Kill ', trx_mysql_thread_id, '; ')
From Information_schema.innodb_trx
where Timestampdiff (Minute,trx_started,now ()) >= 1;
Declare continue handler for not found
Set no_more_long_running_trx=1;

Open C_tid;
Repeat
Fetch C_tid into V_sql;
Set @v_sql =v_sql;
Prepare stmt from @v_sql;
Execute stmt;
deallocate prepare stmt;
Until No_more_long_running_trx end repeat;
Close C_tid;
End
$
delimiter;

MySQL event automatic kill runtime time-out SQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.