Enable Mysql Slow Query Logging

From Brian Nelson Ramblings
Jump to: navigation, search

Enable Mysql Slow Query Logigng/Mysql Query Logging

Are you having mysql problems with your Magento installation. Did you know you can enable mysql logging directly from within Magento? Let talk about enabling database logging with Magento.

You can enable this feature in your Mysql.php file.

vim lib/Varien/Db/Adapter/Pdo/Mysql.php

Are you looking to enable slow log querying or log all queries?

Enable Slow Log Querying in Magento


protected $_debug = true;
protected $_logQueryTime = 0.05  // Change to what you consider slow
protected $_logAllQueries = false; // Must be false or it logs everything
protected $_debugFile = 'var/debug/pdo_mysql.log';

Enable Mysql Querying in Magento


protected $_debug = true;
protected $_logAllQueries = true;
protected $_debugFile = 'var/debug/pdo_mysql.log';

Just remember to turn this feature off once your done, as it will eat up your disk space in a hurry.

Another field you can change is the callstack this will help determine what is making the database call.

protected $_logCallStack = true;

Also, while debugging to help narrow down the issue, you should disable the site from outside visitors.

Disable Access to Your Magento Store

Add the following to the top of your .htaccess file.

Order deny,allow
Deny from all
Allow from <youripaddress>

Happy Magento Debugging