Monday, August 26, 2013

Log SQL queris to table in MySQL(>5.1.12)

FIre the following in the given order in you MySQL AB

  1. Execute SET GLOBAL log_output = 'TABLE';
  2. Execute SET GLOBAL general_log = 'ON';
  3. select * from  mysql.general_log 

mysql.general_log : This table contains following columns

  • event_time
  • user_host
  • thread_id
  • server_id
  • command_type
  • argument

argument column stores the query fired in database.

If you want the output to be stored in file then you can use the following
  1. SET GLOBAL log_output = "FILE";
  2. SET GLOBAL general_log_file = "/path/to/your/logfile.log"
  3. SET GLOBAL general_log = 'ON';

No comments:

Post a Comment