使用tcpdump命令抓取sql

#!/bin/bash

#this script used montor mysql network traffic.echo sql

tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e ' while(<>) { chomp; next if /^[^ ]+[ ]*$/; if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i) { if (defined $q) { print "$q "; } $q=$_; } else { $_ =~ s/^[ ]+//; $q.=" $_"; } }'

原文地址:https://www.cnblogs.com/liuzhenguo/p/14915400.html