How can we help you today?

How to Enable MySQL Query Logging for Magento 1.x

Created by: Rens Zuurbier

Modified on: Fri, 29 May, 2020 at 9:34 AM


Sometimes when debugging complex performance issues, it can be useful to log all database queries to a log file.

Superusers are used to do this changing the query logging settings of the MySQL server.

As enabling this requires root permissions, this functionality is not available to Hypernode users. 

Luckily Magento provides it's own mechanism to log all queries in a log file. 

TABLE OF CONTENTS

Enabling Query Debug Logging in Magento

To turn on Magento's own query logging mechanism, edit /data/web/public/lib/Varien/Db/Adapter/Pdo/Mysql.php:

Now look for the line containing $_debug and change false to true:

protected $_debug               = true;

Sometimes you need to flush your cache before the first queries are logged. 

Log Destination

By default, Magento logs to the /data/web/public/var/debug/pdo_mysql.log 

Warning: Turning query logging on is very resource intensive and causes the show to slow down considerably! Don't forget to change $_debug to false when you are done debugging your issue. 

R
Rens is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.