ºìÁªLinuxÃÅ»§
Linux°ïÖú

MySQL SQL ProfilerÐÔÄÜ·ÖÎöÆ÷

·¢²¼Ê±¼ä:2006-10-06 12:02:06À´Ô´:ºìÁª×÷Õß:yeliming
×÷Õß:qlks

¿´µ½ºÜ¶àÅóÓÑÎÊMySQLµÄÐÔÄÜ·ÖÎöÆ÷
ÒòΪMySQLÔÚÕâ·½Ãæ×öµÃ±È½Ï²î£¬Ò²¿ÉÄÜÎÒ²»ÖªµÀ
ûÓÐMicrosoftµÄSQL Profiler,ҲûÓÐOracleµÄAuditºÍAWR
ËùÒÔÎÒÃǺÜÄѵõ½Ò»Ð©SQLÓï¾äµÄͳ¼Æ£¬ÕâÒ²¸øÎÒÃǵ÷ÓÅ´øÀ´ÁËÀ§ÄÑ
¸üÄѵÄÊǶÔMySQLµÄ×·×Ù
ÒÔǰд¹ý¸ö£¬²»¹ýÔÚ¿´¹ýmysqlÍøÕ¾ÉϵÄÒ»¸öbash½Å±¾ºó£¬¾õµÃ×Ô¼ºµÄÄǸö¾ÍÊÇСÎ×¼û´óÎ×ÁË
ÏÖÄÃÀ´·ÖÏí¸ø´ó¼Ò£¬ºÜ¼òµ¥
# È¡µÃÍø¿¨eth0ÉϵÄËùÓвÙ×÷
[code]time tcpdump -i eth0 -s 1500 -w 20060427-db-traffic-01.dmp[/code]
# Õâ¸ö¿ÉÒÔÖ¸¶¨Ìض¨IPÇëÇóµÄ²Ù×÷£¬¿ÉÓÃÓÚ×·×Ù
[code]time tcpdump -i eth0 -s 1500 src host 192.168.2.10 -w 20060427-db-traffic-01.dmp[/code]
# Õâ¸öÊǸñʽ»¯Êä³öÄãÒª½á¹û
[code]strings 20060427-db-traffic-01.dmp | grep -i 'select' | awk '{printf("%s %s %s %s\n", $1,$2,$3, $4);}'| sort| uniq -c | awk '{printf("%06ld %s %s %s %s\n", $1,$2,$3,$4,$5);}'|sort[/code]

µÃµ½µÄ½á¹û:
[code]cpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 1500 bytes
12000 packets captured
12000 packets received by filter
0 packets dropped by kernel
real 0m8.666s
user 0m0.006s
sys 0m0.016s
--------
000001 select last_insert_id() from system_parameter
...
000122 select count(1) from visit_tracking
000122 select visitor_id
000800 select web_page_id , web_page_type_id
000800 select web_page_type_id , name
003200 select count(1) from hit_count
006400 select pd.parameter_value,
006400 select rp.user_id , rp.update_time[/code]

¿ÉÒÔ¿´µ½Ö´Ðи÷ÖÖselectµÄ´ÎÊý£¬µ±È»¸ÄһϾͿÉÒÔ¿´insert,updateÕâÖÖ²Ù×÷´ÎÊý
ÅäºÏlog-slow-queries£¬Äã¿ÉÒÔ½øÒ»²½µÄÓÅ»¯
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ