How to catch MySQL SQL with tcpdump in Linux

How to catch MySQL SQL with tcpdump in Linux

Introduction

This idea of post is from my previous one: Liferay and P6spy, with the help of P6spy, we can get the formatted Hibernate SQL without "?" ,but it is not so convenient, so are there any way to do the same things, as we all know that MySQL uses port 3306 to monitor infos as default. now the the script is coming....... .

 

Script for

#!/bin/bash

#this script used monitor mysql network traffic.echo sql
tcpdump -i eno1 -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\n"; }
        $q=$_;
    } else {
        $_ =~ s/^[ \t]+//; $q.=" $_";
    }
}'
 
 
 
 
Question:
q:  Why I have not find any SQL in my console ?
 
 w: I am also met the same issue at first, with the helps of Dale, it works. here is the solution:

   change eno1 to any.for the reason:

 "Localhost is not transmitted through the network card, and the 127.0.0.1 is through the network card transmiss in." 
 
 
 
ScreenShot

1
Blogs