接到业务需求,要我统计哪个应用访问了哪些表,一般来讲可以通过:
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了