So, I’m trying to figure out how to log the SQL statements that would be run, without actually having an active mySQL server.
The problem I’m trying to solve is right now we’re writing data to both a remote mySQL instance, as well as a local (archive data). We’re logging to a local as a backup in case the remote becomes unreachable/goes down/etc.
So, what we’d like to do instead is log the SQL statements locally (we’re going through Spring JDBC Template w/variable replacement), so not quite as easy as taking the SQL we piece together ourselves and write it to a file.
I did find log4jdbc which looks great, except we’d still need a local mySQL instance active, even if it’s just using the blackhole engine. I did think maybe we could just use the log4jdbc on the remote server, but if the connection goes away, will the JDBCTemplate even try and run the queries on the underlying JDBC driver objects before getting the failure? Most pooling mechanisms will validate the connection before returning it, so it’d still just fail before the query had a chance to run & get logged.
So, who has any bright ideas?
Mark O’Connors solution is probably the best in general, but the way we solved this was to simply write out the data as CSV files formatted to be ready for import via a load data infile statement.