1丐谋,簡(jiǎn)介
1)類似
performance_schema.replication_applier_status_by_worker
表汹桦,主從同步的時(shí)候出現(xiàn)error侦锯,mysql會(huì)在其中記錄錯(cuò)誤信息四濒,用于解決同步問題蔬螟。
desc performance_schema.replication_applier_status_by_worker
select * from performance_schema.replication_applier_status_by_worker\G;
2)mysql會(huì)把當(dāng)前正在運(yùn)行的mysql線程信息實(shí)時(shí)更新到processlist表中。The PROCESSLIST table provides information about which threads are running.
desc information_schema.processlist;
show processlist : 如果當(dāng)前用戶沒有process 的privilege铁孵,只能看到屬于自己的threads info锭硼。如果有process權(quán)限,則可以看到其他用戶的線程信息蜕劝。
show full processlist == select * from information_schema.processlist;
2,字段說明
- id - 線程ID檀头。對(duì)于慢查詢,可以使用kill id來終端該慢sql岖沛。
user - 用戶eg:system user用于主從復(fù)制暑始,maxscale用于mysql proxy代理,另外我們自己創(chuàng)建的用戶root婴削、admin廊镜、reader等用戶。
db - 當(dāng)前線程連接的數(shù)據(jù)庫
host - 客戶端的IP(直連的ip唉俗,比如使用了代理嗤朴,則顯示的是代理的ip)
command - 當(dāng)前執(zhí)行的命令配椭,比如最常見的:Sleep,Query雹姊,Connect 等股缸,sleep說明線程是空閑的狀態(tài),會(huì)有一個(gè)默認(rèn)的超時(shí)時(shí)間吱雏。maintains persistent connections比如連接池
time - 消耗時(shí)間敦姻,單位秒。(query說明執(zhí)行查詢的時(shí)間)
state - 執(zhí)行狀態(tài)Waiting for master to send event;
Master has sent all binlog to slave; waiting for more updates
info - 執(zhí)行的SQL語句歧杏。
3镰惦,慢查詢
1)查找執(zhí)行超過1分鐘的線程信息。
select * from information_schema.processlist where command != 'Sleep' and time > 60 order by time desc;
2)不要輕易kill犬绒,注意看是否是system user或者是maxscale等代理監(jiān)控的用戶陨献。
3)確定是慢查詢的時(shí)候,可以執(zhí)行kill id的操作懂更。
1)命令行查看慢查詢
mysql -ureader -pread -e 'show full processlist' | grep "select "
2)kill慢查詢
增加參數(shù)| awk '{ if($6>100) print $0 }' | awk '{print $1}' | xargs mysqladmin kill
其中單引號(hào)中的被大括號(hào)括著的就是awk的語句眨业,注意,其只能被單引號(hào)包含沮协。其中的$1..$n表示第幾例龄捡。注:$0表示整個(gè)行。
4慷暂,mysql慢查詢kill工具聘殖。
https://www.percona.com/doc/percona-toolkit/LATEST/index.html
殺慢查詢工具,和檢測(cè)冗余和重復(fù)索引的工具行瑞。
/usr/local/bin/pt-kill --user root --password root --busy-time 2 --match-command Query --print --kill --victims all --interval 2 --log /opt/mysql_slow_query.txt --daemonize