Feb 10, 2022

Slow query log purge in MySQL

There are manly 3 steps...

1. Rename existing log file with _old.

2. Connect mysqladmin using socket and use  flush-logs.

3. Delete _old file created in first step.

 

Get the show query log location:

mysql> show variables like slow_query_log %';

Get the socket file location:

mysql> show variables like 'socket%';

In my case I got the info like below…

/u01/app/logs/DB_instance/slow-query-DB_instance.log

/var/run/DB_Instance/DB_instance.sock

Now go to the Log location and renaming slow query file…

mv slow-query-DB_instance.log slow-query- DB_instance.log_old 

 

Flush-log using mysqladmin

/u01/app/mysql80/bin/mysqladmin  flush-logs --socket=/var/run/DB_Instance/ DB_Instance.sock

You can check show query log file. There will be a new log file.

Now delete old log file

rm slow-query-DB_Instance.log_old

 

All set....

No comments:

Post a Comment

If you have any doubt or question, please contact us.