How to catch MySQL SQL with tcpdump in Linux

David Zhang
David Zhang
Less Than a Minute Read

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

Page Comments

The Technicalities of Static Sites

David Oliveira Montenegro
View Blog >

Customization is Dead! Long Live Customization!

David H Nebinger
View Blog >
customization banner image.png

Public Bug Bounty Program

David H Nebinger
View Blog >
bugbounty.png
Showing 1 to 3 of 3 entries.