Forrest logo
back to the mysql tool

mysql:logs:binary:purge:interval

Remove all binary logs that are older than a given interval (in days).
$ mysql --execute "PURGE BINARY LOGS BEFORE NOW() - INTERVAL ${interval_in_days} DAY"
try on your machine

This command is used to purge (delete) binary logs in MySQL that are older than a specified interval.

Let's break down the command step by step:

  • mysql: This is the command-line tool to communicate with the MySQL database server.

  • --execute: This option is used to specify the SQL statement that should be executed.

  • \"PURGE BINARY LOGS BEFORE NOW() - INTERVAL ${interval_in_days} DAY\": This is the SQL statement that is being executed. It uses the PURGE BINARY LOGS command to remove binary logs.

The SQL statement has two main parts:

  1. NOW() - INTERVAL ${interval_in_days} DAY: This calculates the date and time that is the specified number of days before the current date and time. The ${interval_in_days} is a placeholder for the actual number of days, which can be supplied as a parameter when executing the command.

  2. PURGE BINARY LOGS BEFORE: This is the command to delete binary logs that are older than the specified date and time.

When you run this command, it connects to the MySQL database server, executes the specified SQL statement (PURGE BINARY LOGS BEFORE NOW() - INTERVAL ${interval_in_days} DAY), and purges the binary logs that are older than the specified interval.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mysql tool