Enable MySQL Protocol Tracing

Protocol tracing gives you the exact bytes that are being sent back and forth between Java and MySQL (via the JDBC driver, I guess). It results in something like this in the Eclipse console:

    Tue Oct 23 13:18:22 CDT 2007 TRACE: ReadAheadInputStream.readIfNecessary([B@131f919,0,49) not all data available in buffer, must read from stream
    Tue Oct 23 13:18:22 CDT 2007 TRACE:   ReadAheadInputStream.fill(49), buffer_size=16384, current_position=0, need to read 49 bytes to fill request, underlying InputStream reports 49 total bytes available, attempting to read 49 bytes.
    Tue Oct 23 13:18:22 CDT 2007 TRACE: reuseAndReadPacket() payload:
    ff 1e 04 23 34 32 53 32     . . . # 4 2 S 2 
    32 55 6e 6b 6e 6f 77 6e     2 U n k n o w n 
    20 63 6f 6c 75 6d 6e 20     . c o l u m n . 
    27 63 6f 75 6e 74 72 79     ' c o u n t r y 
    27 20 69 6e 20 27 66 69     ' . i n . ' f i 
    65 6c 64 20 6c 69 73 74     e l d . l i s t 
    27    

To enable it, you need to pass an additional traceProtocol option in your JDBC connection URL.

   <bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://db:3306/db1?traceProtocol=true"/>
      <property name="username" value="user"/>
      <property name="password" value="pwd"/>
   </bean>

MySQLProtocolTrace (last edited 2008-07-09 06:21:25 by localhost)