Decode your binary format ProxySQL query log.
- Go v1.11 or later
go mod downloadcd cmd/decodergo build
After you've build the decoder, just run the executable.
5D 00 00 00 00 00 00 00first 8 bytes is the length of a message, this one.00next byte denounce that this is a ProxySQL log message or not, if not00, not valid.
The next after this line needs read_encoded_length function which itself needs mysql_decode_length function.
0Athis is the thread id because it is less than or equal0xFB, convert touint64.06this is the length of username because it is less than or equal0xFB, convert touint64.64 69 64 61 73 79is the username in ASCII.12this is the length of schema because it is less than or equal0xFB, convert touint64.69 6E 66 6F 72 6D 61 74 69 6F 6E 5F 73 63 68 65 6D 61is the schema in ASCII.0Fthis is the length of client address because it is less than or equal0xFB, convert touint64.31 32 37 2E 30 2E 30 2E 31 3A 33 32 38 32 30is the client address in ASCII.FEthis tell us to read the next 8 bytes asuint64.FF FF FF FF FF FF FF FFthis is the HID inuint64, ifHID == UINT64_MAXthen we don't have server address to read.FEthis tell us to read the next 8 bytes asuint64.91 00 B3 4A 28 86 05 00this is query start time in UNIX microseconds inuint64.FEthis tell us to read the next 8 bytes asuint64.91 00 B3 4A 28 86 05 00this is query end time in UNIX microseconds inuint64.FEthis tell us to read the next 8 bytes asuint64.D6 1F BA 14 4D 1F 23 AEthis is query digest inuint64, but it needs to be separated into two uint32 and then it can be printed into hexsprintf("0x%X%X", n1, n2) == 0x14BA1FD6AE231F4D.0Cthis is the length of the actual query because it is less than or equal0xFB, convert touint64.2E 30 2E 31 3A 33 32 38 32 30 00 A5this the actual query in ASCII.
Then we can go to the next line and repeat.
To decode part length, first we must take the first byte of the part. Then we check if:
- It is less or equal than
0xFB. If so we take this byte as the message length. - It is equal to
0xFC. If so, we take 2 bytes as the message length. - It is equal to
0xFD. If so, we take 3 bytes as the message length. - It is equal to
0xFE. If so, we take 8 bytes as the message length.