Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2015 November MySQL: How to Log General and Long Running Queries into Log Table

MySQL: How to Log General and Long Running Queries into Log Table

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing the different parameters to enable logging for General and Long running queries in MySQL.

Using shared approach, you don’t require to restart your MySQL Server. You can easily configure this log parameter, and you can see the output in Log table.

As a Database Administrator, it is our responsibility to log the all different kinds of queries because the log is our primary requirement for any troubleshooting.

First check the current status of the different Log Parameters:

1
SHOW VARIABLES LIKE '%log%';

Using above statement, you can check the current value of log parameter.

Now enable logging for general query and save the output into “mysql.general_log” table:

1
2
3
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
SELECT *FROM mysql.general_log;

Now enable logging for long running queries:

1
2
3
SET GLOBAL slow_query_log = 1;
SET GLOBAL long_query_time= 1;
SET GLOBAL log_queries_not_using_indexes= ON;

Sometimes, it is required to execute the FLUSH command of the log to get immediate updates into the Log Table.

1
FLUSH LOGS;

Nov 15, 2015Anvesh Patel
SQL Server: Script to Enable and Disable XP_CMDSHELL ConfigurationSQL Server: Script to Hide all Databases in SSMS
Comments: 3
  1. Carl
    December 6, 2015 at 9:19 pm

    I wwas suggested this website by my cousin. I’m not sure whether
    this post is written by him as nobody else know sch
    detailed about my trouble. You’re incredible! Thanks!

  2. blanch
    December 14, 2015 at 7:47 pm

    Heey There. I found your blog using msn. This is a very well written article.
    I will be sure to bookmark iit and come back to
    read more of your useful information. Thanks for the post.

    I will certainly comeback.

  3. naveen Reddy
    September 20, 2017 at 7:04 am

    Good Job bro…

Anvesh Patel
Anvesh Patel

Database Engineer

November 15, 2015 MySQL, MySQL DBA ScriptAnvesh Patel, database, database research and development, dbrnd, general_log, log_output, log_queries_not_using_indexes, long_query_time, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks, slow_query_log
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....