Thursday, March 17, 2022

[FIXED] Create date wise log of executed queries on MySql

Issue

Sometime I make changes on local database but forgot to write/copy query to made changes.

I want to create log file which contain all changes I made in Database with:

 log file with date 
eg. mySql_log_03_10_2019.log

File must created on @ 12:00 AM

Many developers like me may face this problem.


Solution

After searching, I found following ways:

  • Using table
  • Using log file

First run

SET GLOBAL general_log = 'ON';

Then

For table:

SET global log_output = 'table';

For retrieve for particular date:

select * from mysql.general_log WHERE DATE(event_time) = 'yyyy-mm-dd'

For log file:

SET GLOBAL general_log_file = "path to log file";

like. "D:/xampp/mysql/data/logs/mysql_general.log"

Both methods have pros/cons.(table/file size ...)

Hope it help someone.



Answered By - Satish

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.