Sometimes Magento does something and it’s just not obvious why. We’ve all heard “why aren’t my products showing up?” more times than we can count. Magento’s object model for building queries is great, but sometimes you just need to see the sql that’s being run on the database in order to know what’s really going on.
In the past I’ve used the general log in mysql. That can be a great source of information, but, depending on the version of mysql, it can be a pain to set up. Other times I’ve inserted logging code into various db classes in order to print out queries that are being run, but I always have to find the right place again. But today I stumbled on this blog entry – http://blog.nexcess.net/2011/04/15/logging-database-queries-in-magento/ that spells out exactly how you can turn on some (as far as I know) undocumented logging functionality that is built right in to the Magento data access layer. Kudos to the author and thanks for sharing!