Correct Method for deleting MySQL logs

Source: Internet
Author: User

1. Find

Mysql> show binary logs;

+ ------ + ---- +

| Log_name | file_size |

+ ------ + ---- +

| Mysql-bin.000001 | 150462942 |

| Mysql-bin.000002 | 125 |

| Mysql-bin.000003 | 106 |

+ ------ + ---- +

2. Delete the bin-log (before removing the mysql-bin.000003 without containing the mysql-bin.000003)

Mysql> purge binary logs to 'mysql-bin.000003 ';

Query OK, 0 rows affected (0.16 Sec)

3. query results (only one record is available now .)

Mysql> show BINLOG events/g

* *************************** 1. row ***************************

Log_name: mysql-bin.000003

POs: 4

Event_type: format_desc

Server_id: 1

End_log_pos: 106

Info: Server Ver: 5.1.26-RC-log, BINLOG Ver: 4

1 row in SET (0.01 Sec)

(Mysql-bin.000001 and mysql-bin.000002 have been deleted)

Mysql> show binary logs;

+ ------ + ---- +

| Log_name | file_size |

+ ------ + ---- +

| Mysql-bin.000003 | 106 |

+ ------ + ---- +

1 row in SET (0.00 Sec)

(Other deleted formats are used !)

Purge {master | binary} logs to 'Log _ name'
Purge {master | binary} logs before 'date'
Deletes all binary logs listed in the log index before the specified log or date. These logs will also be deleted from the list of records in the log index file, so that the given log becomes the first.
For example:
Purge master logs to 'mysql-bin.010 ′;
Purge master logs before '2017-06-22 13:00:00 ′;
Clear BINLOG 3 days ago
Purge master logs before date_sub (now (), interval 3 day );
The date argument for the before variable can be in the 'yyyy-MM-DD hh: mm: ss' format. Both master and binary are synonyms.
If you have an active slave server that is currently reading one of the logs you are trying to delete, this statement does not work, but fails with an error. However, if the slave server is slave and you happen to have cleared one of the logs it wants to read, the slave server cannot be copied after it is started. This statement can be run safely when the slave server is being copied. You do not need to stop them.
To clear logs, follow these steps:
1. Use show slave status on each slave server to check which log it is reading.
2. Use show Master logs to obtain a series of logs on the master server.
3. Identify the earliest logs among all slave servers. This is the target log. If all slave servers are updated, this is the last log in the list.

4. Back up all the logs you want to delete. (This step is optional, but is recommended .)

5. Clear all logs, but not the target logs.

Set in contab:

0 1 *** 'mysql-uroot-e' purge master logs before date_sub (now (), interval 3 day );''

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.