How to enable the MySQL Slow Query log in ubuntu

enable the MySQL Slow Query log in ubuntu

When developing your own internet application its necessary that pages load quickly. The most important factors that confirm page response times is that the time taken to SQL queries, however does one recognize that SQL queries at fault?

The answer is MySQL's slow question log. By facultative this feature, a log file is formed which will tell you on every time a query takes too long to execute. you'll be able to then use this data to either optimize your info or rewrite the SQL.

For this guide i'll assume you have already installed MySQL or MariaDB. These article is supporting Ubuntu 16.04 however the identical approach works on different UNIX operating system.

Step 1: modify the Slow question log

First, confirm your MySQL configuration file "my.cnf" is located - on Ubuntu 16.04 it's /etc/mysql/my.cnf whereas on different distributions it's typically /etc/my.cnf

Edit the MySQL configuration file and add the subsequent lines at the end:

 slow_query_log_file = /var/log/mysql/slow.log  
 long_query_time = 1  

Save your changes and restart MySQL

 service mysql restart  

Step 2: examining the slow question log

Start looking the slow log:

 tail -f /var/log/mysql/slow.log  

At startup, you may see output like this:

 /usr/sbin/mysqld, Version: 5.7.12-0ubuntu1-log ((Ubuntu)). started with:  
 Tcp port: 3306 OS socket: /var/run/mysqld/mysqld.sock  
 Time Id Command Argument  

Now, mistreatment your browser begin interacting together with your internet application and note the queries that are shown. shortly you will notice one or 2 queries that are systematically shown.


  1. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Software Testing Training in Chennai
    Software Testing Course in Chennai
    AWS Training in Chennai
    Blue Prism Training in Chennai
    CCNA Course in Chennai
    Cloud Computing Training in Chennai
    Data Science Course in Chennai
    Software Testing Training in Velachery

  2. This is an awesome post.Really very informative and creative contents.
    Wordpress Development company in Chennai

  3. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai