MySQL – How to Enable Slow Query Logs (Linux)

In MySQL 5.6, they introduced a different way of logging slow queries compared to previous versions. This article will show you how to quickly, and correctly enable the slow query log which is extremely useful for debugging application performance issues.

Enable Slow Query Log in MySQL

  1. Login to your MySQL host
  2. Open the my.cnf file in your favorite text editor:vi /etc/my.cnf
  3. Add the following properties:
    long_query_time=1
    slow_query_log=1
    slow_query_log_file="/var/log/mysql/log-slow-queries.log"

    long_query_time – Defines the minimum threshold for the “slow query” designation. 1 means log all queries that take more than 1s to executeslow_query_log – Value of 1 means enable. 0 means disableslow_query_log_file – Log file path. This path generally be at the same location as mysql-error.log
  4. Reload the MySQL configuration (will not cause an interruption)
    service mysql reload
See also  Quick Guide: Install MySQL on Mac Using Brew

Support us & keep this site free of annoying ads.
Shop Amazon.com or Donate with Paypal

2 thoughts on “MySQL – How to Enable Slow Query Logs (Linux)”

Leave a Comment