Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL manages long-running queries

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Select concat ('kill ',id,';') from information_schema.processlist where time >= 2 -- and user = 'Business Account' and command not in ('sleep','Connect') and state not like ('waiting for table%lock'); and info like '%Metabase%'mysql -uroot -s -N -p -h -e "select concat ('kill ',id,';') from information_schema.processlist where INFO like 'SELECT xxx FROM %'"> kill.sqlRDS provides the storage process: create event my_long_running_query_monitor schedule every 5 minutes starts'2015-09-15 11:00:00'on completion preserve enable dobegin declare v_sql varchar(500); declare no_more_long_running_query integer default 0; declare c_tid cursor for select concat ('kill ',id,';') from information_schema.processlist where time >= 3600 and user = substring(current_user(),1,instr(current_user(),'@')-1) and command not in ('sleep') and state not like ('waiting for table%lock'); declare continue handler for not found set no_more_long_running_query=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_query end repeat; close c_tid;end;

Reference: help.aliyun.com/knowledge_detail/41735.html? spm=a2c4g.11186631.2.20.51106998SvntYb

Parameters in RDS

loose_max_statement_time

shell script for managing long queries #!/ bin/bashpassword=xxxxxxmysql -uroot -p$password -N -s -e "select concat ('kill ',id,';') from information_schema.processlist where time >= 300 -- and user = 'Business Account' and command not in ('sleep','Connect') and state not like ('waiting for table%lock');" > killmysqlsession.txt#cat killmysqlsession.txt |while read line#do#echo $line#mysql -uroot -p$password -e "$line"#donemysql -uroot -p$password < killmysqlsession.txt#or login instance source killmysqlsession.txt

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report