Query Recorder is a new tool that allows developers to record queries while working in the WordPress admin. The plugin was created by Brad Touesnard, author of the popular WP Migrate DB plugin. Touesnard introduced Query Recorder earlier this month at WordCamp Miami during his presentation on database deployment strategy.
Once installed, the plugin allows you to create recordings that save queries run by your theme or plugins. The recordings are sent to a sql file located in your /uploads/ directory.
The settings page gives you the option to set exclusions for certain types of queries and elect to omit or record queries that begin with insert, update, delete, drop, and create.
Clicking the button in the admin bar will start or stop the recording:
Once you’ve made a recording, open up the SQL file in your uploads folder and you’ll find your saved queries. In the example below you can see that I’ve enabled and disabled some plugins and themes.
Query Recorder can be particularly useful when working on a local installation of WordPress. You can record queries as you’re setting up a theme or plugin and create a SQL script that can be run later when deploying to another site. You can quickly test plugins and themes and then import the sql file when setting them up on a staging or live site. This is much easier than having to repeat those exact steps again in another environment.
I tested the plugin and it works exactly as advertised. Download Query Recorder for free from the WordPress plugin directory. If you’d like to contribute to the project, it’s also hosted on Github.
That’s a pretty cool plugin, although I always prefer to run the MySQL server with
--general_log
when debugging, that way I also catch the naughty plugins by-passing$wpdb
callingmysql_query
directly :)Quick note — queries are logged into a publicly accessible directory. This is a mistake many plugins do/did, even fairly popular ones like W3 Total Cache, which at some point stored database and object cache publicly accessible on disk. You definitely don’t want to leak your database queries, which can contain e-mails, password hashes, authentication tokens to external services like Twitter, Google, etc.