Brad
Brad

Reputation: 95

Log SQL Queries to File if MySQL DB Connection fails

I have a Perl script for writing data to a MySQL DB, runs fine. Question I have is if there is a proper method to log prepared queries to a local file if the connection to the MySQL DB times out or fails? If the connection fails or timeouts, does the Perl-DBI obj even allow preparing MySQL statements?

Thank you!

Brad

Upvotes: 0

Views: 182

Answers (1)

Ask Bjørn Hansen
Ask Bjørn Hansen

Reputation: 6953

There's nothing like that built into DBI or the MySQL client. It's hard to make it work correctly in a generic fashion, too, as many of the edge/exception cases really are application specific.

This sort of thing is also prone to error as you're doing something relatively complicated only when things are already going badly. If MySQL being unavailable is a common case or it's too important to stop/timeout/retry in case of errors, see if you can write the data to another stream (always) that is better at handling errors. For example you could push it into scribe on the local server and have another program read the data from scribe and insert/update MySQL. Scribe takes care of the local buffering to disk and such.

Of course that just has different trade-offs in different error scenarios.

Upvotes: 1

Related Questions