134
技術社區[雲棲]
獲取訪問MySQL的應用
接到業務需求,要我統計哪個應用訪問了哪些表,一般來講可以通過:
1.show full processlist;
2.SELECT HOST FROM information_schema.processlist where user='dbname' and INFO like '%tbname%'"
上述兩種方法都可以,但是第一種不方便統計,為此我選用了第二種方法:
#!/bin/bash
COUNTER=0
tmp_file=$1
while [ $COUNTER -lt 10000 ];
do
ss=`mysql -uroot -N -e"SELECT HOST FROM information_schema.processlist where user='dbname' and INFO like '%tbname%'";`
echo $ss>>${tmp_file}
let COUNTER=COUNTER+1
done
然後
awk -F":" '{print $1}' ${tmp_file}| sort | uniq
就可以找出訪問表的ip了
最後更新:2017-10-17 20:03:25