As an exercise I wrote a proof of concept of a proxy for MySQL. It isn't using any code from the MySQL Server, only some headers files. I only used the internals document and implemented the server-side protocol of it.
After having the basic stuff running:
- socket handling
- mysql wire-protocol
- len-encoding of some fields
- field-types
- the life-cycle of a connection
... I could finally use the mysql command line client to connect to my dummy-server. The mysql-clients sends a few statements at startup:
select @@version_comment LIMIT 1; select USER();
Detecting slow queries
Proxying requests is pretty simple, just speak the server protocol one side and the client on the other just forward the packets as the come in. Pretty straight-forward.
As extension of the initial task we want to find out which queries are causing a …
[Read more]