Select Page

MySQL Query Logging

MySQL has an option to log all queries to a log file, stupidly though you need to restart the server to start/stop this log, its a bit lame, it also adds a lot of overhead to your box. I had the idea some time ago to use libpcap to figure out what gets sent to the server and started the code, I’ve mostly finished this now.
The MySQL protocol is undocumented but there is a reverse engineered protocol doc here. It is a tad outdated and I’ve found some queries that does not get parsed perfectly using the info there, I’ll look into those some more.
Here are some sample outputs from my code:

# ./mysqldump.pl -i mysql.cap
17:08:44: SET autocommit=1
17:08:44: SELECT last_insert_id()
17:08:44: rollback

It also has a more verbose option:

# ./mysqldump.pl -i mysql.cap -v
MySQL Packet:
Length          : 24
Packet Number   : 0
Packet Command  : 3
SQL Command     : SELECT last_insert_id()
Packet Header:
Source   : 192.168.1.1
Dest     : 192.168.1.2
S.Port   : 47241
D.Port   : 3306
Length   : 77
Timestamp: 1150128523.750337

I could make the script do its own dumping using libpcap it’s pretty easy but I prefer to only let it read tcpdump files, we get a LOT of queries (> 600 per second) and I don’t want slow perl code to affect the servers, tcpdump is pretty fast and efficient.
I use Net::Pcap and NetPacket::TCP to extract the packets from the file, decoding the MySQL commands is pretty easy then:

$plen = ord(substr($pkt, 66, 3));
$pnum = ord(substr($pkt, 69, 1));
$pcmd = ord(substr($pkt, 70, 1));
$cmd  = substr($pkt, 71);

The offsets etc is defined in the documentation linked too above, $cmd will now hold the actual query ran against the server, but only where $pcmd == 3.
I’ll upload the code for this in the next few days just letting a few people do some beta testing for me first.
UPDATE: You can now get the code here.

AppZapper

I’ve heard about AppZapper from Mike and had a look at it but wasn’t quite sold on it.


Today I got the latest release of the Neat Little Mac Apps podcast and it reviewed this app, it also includes a promo code for the next 3 weeks which gives you $3 discount. For less than 6 pounds how can you say no after listening to that review? I grabbed a copy and really like it, if you’re into installing and uninstalling apps a lot on your mac, you should get it too.
The basic idea on a mac when it comes to installing and uninstalling software is simply to drag the application anywhere you want and thats all. When it comes to uninstalling, just drop it in the trash, simple. Unfortunately most applications have a lot of support and related files, things like preferences, logs, caches etc and the typical uninstall method does not get rid of these.
This is where AppZapper comes in, it hunts down all the crud that an app puts everywhere and deletes those along with the app, neat. Using the example in the image above, if I had just done the usual drop-in-trash method of uninstall I’d have left on my drive 57MB of crap.
My home directory is full of junk, should have bought this app ages ago.

Why I don’t use Ruby On Rails.

It’s simple, the community around it are a bunch of bigots. See this post on macslash.
The poor guy asks for something simple and gets flamed to death by a bunch RoR idiots who are acting like they need to justify their choices, no thank you. You’d swear its the new third reigh.
There are countless reasons why someone would want to stick to PHP, why does he need to face up to this kind of abuse just because he made a choice?

Spotlaser

Spotlight is the supposedly all-singing-and-dancing desktop search tool from Apple, it is pretty neat and supports a ton of useful things relating to meta data and so forth, I’ve blogged about it before showing how you can use it on the command line to gain access to these functions.
On the GUI side of things it’s a bit crap, you have the top-right spotlight box that you can type into and it features a pretty dismal command language for doing power searches. You can also use Finders tool to do finds using Spotlight, it’s OK I guess but not kewl enough to convince me to actually integrate Spotlight into my daily life.
I toyed with writing a GUI frontend to Applescript this last weekend and got pretty far, you could restrict searches, do AND or OR searches, date matches and the like, and it would open the results in the Finder find interface but coding Applescript GUI’s doesn’t really excite me so I didn’t go further with it.
Today over at FreeMacWare.com I saw mention of Spotlaser and it’s pretty sweet, its a full frontend to all the features of Spotlight and using it you can really see what is possible, hopefully Apple will soon introduce their own advanced front-end to Spotlight, till then, Spotlaser is the way to go.


Above is a screenshot of it in action, its donationware, so grab a copy now.

New iMac

I mentioned the other day in the comments of my Ubuntu post that my girlfriend decided to get herself a iMac, this weekend we went to pick it up from the Apple store in Regents Street.
After the traumatising walk through soho carrying a computer in my arms when we got it home all seemed fine to begin with, but then when it came time to test out the iSight the thing was dead. It produced either pure white or pure green but nothing else.
I was really dreading taking it back as it would mean she would be without a computer for a while and just general be a total pain, I searched the Apple support forums and they got me nowhere but then I searched the forums and came across someone who had the same problem, they unplugged their iMac from the wall for 30 seconds and that fixed it, I did the same and voila, one happy mac.
So not too bad, but still a bit infuriating.


While we were there I also picked up a iPod Nano for Emma, I’ve not really looked at these in detail before and must say it’s a very sexy bit of kit. Though comparing it to my 3 year old iPod I have doubts about the build quality, for example the plug where the power/doc goes in doesn’t nicely click into place it’s more a matter of forcing it in, not sure if that is normal but it sure is annoying.