MySQL binary logs

Source: Internet
Author: User

Recently, an alarm is triggered when the disk space of the database server is insufficient. In fact, the database file itself is not large, mainly because the binary logs accumulated over the past six months is large, especially databases with master-slave configurations. I checked a lot of information and summarized the commonly used MySQL commands for Binary logs:

1. Binary logs location:

1) view/etc/My. CNF (My. ini in Windows), for example:

Log_bin =/var/mydb/bin-Log

If this setting does not contain a path, place it in datadir =/var/lib/MySQL.

2) check whether the binary log function is enabled in the database:

Mysql> show variables like 'Log _ bin ';
+ --------------- + ------- +
| Variable_name | value |
+ --------------- + ------- +
| Log_bin | on |
+ --------------- + ------- +
1 row in SET (0.00 Sec)

Mysql> show variables like 'Log _ bin ';
+ --------------- + ------- +
| Variable_name | value |
+ --------------- + ------- +
| Log_bin | off |
+ --------------- + ------- +
1 row in SET (0.01 Sec)

If it is off, it will not work as follows :)

2. Check the name and size of the currently running logfile: Show binary logs/show Master logs;

Mysql> show binary logs;
+ ----------------- + ----------- +
| Log_name | file_size |
+ ----------------- + ----------- +
| Bin-log.000011 | 148329 |
+ ----------------- + ----------- +

Mysql> show Master logs;
+ ----------------- + ----------- +
| Log_name | file_size |
+ ----------------- + ----------- +
| Bin-log.000011 | 148329 |
+ ----------------- + ----------- +

Mysql> show binary logs;
Error 1381 (hy000): You are not using binary logging ### binary logs not enabled

3. Clear all binary logs;

1)

Mysql> show Master logs;
+ ----------------- + ----------- +
| Log_name | file_size |
+ ----------------- + ----------- +
| Log-bin.000001 | 259548 |
| Log-bin.000002 | 37200 |
| Log-bin.000003 | 74219 |
+ ----------------- + ----------- +
3 rows in SET (0.00 Sec)

Mysql> Reset master; (on slave, use reset slave. Stop slave before and start slave)
Query OK, 0 rows affected (0.00 Sec)

Mysql> show Master logs;
+ ----------------- + ----------- +
| Log_name | file_size |
+ ----------------- + ----------- +
| Log-bin.000001 | 98 |
+ ----------------- + ----------- +
1 row in SET (0.00 Sec)

4. Clear the specified logs:

Mysql> purge binary logs to 'Log-bin.000012 ';

Clear binary logs before log-bin.000012;

Mysql> purge binary logs before '2017-05-28 12:05:38 ';

Clears the binary logs before the specified time;

5. view the current binary log:

Mysql> show Master status;

6. View binary logs content:

Mysql> show BINLOG events;

Command line:

# Mysqlbinlog/var/log/MySQL/log-bin.000140; or

# Mysqlbinlog -- start-datetime = '2017-07-01 00:00:00 '-- stop-datetime = '2017-07-15 00:00:00'/var/log/MySQL/log-bin.000020>. /tmp. log

7. Set the number of days for Binary logs rollback in my. CNF/My. ini:

Expire_logs_days = 7

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.