本文共 14401 字,大约阅读时间需要 48 分钟。
1 | expire_logs_days = 10 |
1 | set global expire_logs_days = 10; |
1 2 | PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY); show master logs; |
1 2 3 4 | log-bin=mysql-bin #binlog_format="STATEMENT" #binlog_format="ROW" binlog_format= "MIXED" |
1 2 3 4 5 6 | mysql> SET SESSION binlog_format = 'STATEMENT' ; mysql> SET SESSION binlog_format = 'ROW' ; mysql> SET SESSION binlog_format = 'MIXED' ; mysql> SET GLOBAL binlog_format = 'STATEMENT' ; mysql> SET GLOBAL binlog_format = 'ROW' ; mysql> SET GLOBAL binlog_format = 'MIXED' ; |
1 2 | [mysqld] Log-bin=”二进制日志文件存储路径/文件名” (默认路径为数据目录,二进制文件) |
1 2 3 4 5 6 7 8 9 | mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 120 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 | mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | mysql> show binlog events; +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | mysql-bin.000001 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.10-log, Binlog ver: 4 | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ 1 row in set (0.00 sec) mysql> mysql> show binlog events in 'mysql-bin.000001' ; +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | mysql-bin.000001 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.10-log, Binlog ver: 4 | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ 1 row in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> mysql> flush logs; Query OK, 0 rows affected (0.02 sec) mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 167 | | mysql-bin.000002 | 120 | +------------------+-----------+ 2 rows in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | mysql> flush logs; Query OK, 0 rows affected (0.01 sec) mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 167 | | mysql-bin.000002 | 167 | | mysql-bin.000003 | 120 | +------------------+-----------+ 3 rows in set (0.00 sec) mysql> purge master logs to 'mysql-bin.000003' ; Query OK, 0 rows affected (0.00 sec) mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000003 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [root@Betty data] # ll total 176420 -rw-r----- 1 mysql root 68343 Mar 18 13:19 Betty.err -rw-rw---- 1 mysql mysql 6 Mar 18 13:19 Betty.pid -rw-rw---- 1 mysql mysql 56 Feb 21 14:20 auto.cnf -rw-rw---- 1 mysql mysql 50331648 Mar 18 13:19 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Feb 21 14:17 ib_logfile1 -rw-rw---- 1 mysql mysql 79691776 Mar 18 13:19 ibdata1 drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:17 mysql -rw-rw---- 1 mysql mysql 167 Mar 18 13:31 mysql-bin.000001 -rw-rw---- 1 mysql mysql 167 Mar 18 13:35 mysql-bin.000002 -rw-rw---- 1 mysql mysql 120 Mar 18 13:35 mysql-bin.000003 -rw-rw---- 1 mysql mysql 57 Mar 18 13:35 mysql-bin.index drwx------ 2 mysql mysql 4096 Feb 21 14:17 performance_schema drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:02 test [root@Betty data] # [root@Betty data] # cat mysql-bin.index . /mysql-bin .000001 . /mysql-bin .000002 . /mysql-bin .000003 [root@Betty data] # |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [root@Betty data] # [root@Betty data] # cat mysql-bin.index . /mysql-bin .000003 [root@Betty data] # ll total 176412 -rw-r----- 1 mysql root 68343 Mar 18 13:19 Betty.err -rw-rw---- 1 mysql mysql 6 Mar 18 13:19 Betty.pid -rw-rw---- 1 mysql mysql 56 Feb 21 14:20 auto.cnf -rw-rw---- 1 mysql mysql 50331648 Mar 18 13:19 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Feb 21 14:17 ib_logfile1 -rw-rw---- 1 mysql mysql 79691776 Mar 18 13:19 ibdata1 drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:17 mysql -rw-rw---- 1 mysql mysql 120 Mar 18 13:35 mysql-bin.000003 -rw-rw---- 1 mysql mysql 19 Mar 18 13:36 mysql-bin.index drwx------ 2 mysql mysql 4096 Feb 21 14:17 performance_schema drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:02 test [root@Betty data] # |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000003 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> mysql> reset master; Query OK, 0 rows affected (0.01 sec) mysql> mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [root@Betty data] # cat mysql-bin.index . /mysql-bin .000003 [root@Betty data] # ll total 176412 -rw-r----- 1 mysql root 68343 Mar 18 13:19 Betty.err -rw-rw---- 1 mysql mysql 6 Mar 18 13:19 Betty.pid -rw-rw---- 1 mysql mysql 56 Feb 21 14:20 auto.cnf -rw-rw---- 1 mysql mysql 50331648 Mar 18 13:19 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Feb 21 14:17 ib_logfile1 -rw-rw---- 1 mysql mysql 79691776 Mar 18 13:19 ibdata1 drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:17 mysql -rw-rw---- 1 mysql mysql 120 Mar 18 13:35 mysql-bin.000003 -rw-rw---- 1 mysql mysql 19 Mar 18 13:36 mysql-bin.index drwx------ 2 mysql mysql 4096 Feb 21 14:17 performance_schema drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:02 test [root@Betty data] # [root@Betty data] # [root@Betty data] # cat mysql-bin.index . /mysql-bin .000001 [root@Betty data] # [root@Betty data] # ll total 176412 -rw-r----- 1 mysql root 68343 Mar 18 13:19 Betty.err -rw-rw---- 1 mysql mysql 6 Mar 18 13:19 Betty.pid -rw-rw---- 1 mysql mysql 56 Feb 21 14:20 auto.cnf -rw-rw---- 1 mysql mysql 50331648 Mar 18 13:19 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Feb 21 14:17 ib_logfile1 -rw-rw---- 1 mysql mysql 79691776 Mar 18 13:19 ibdata1 drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:17 mysql -rw-rw---- 1 mysql mysql 120 Mar 18 13:41 mysql-bin.000001 -rw-rw---- 1 mysql mysql 19 Mar 18 13:41 mysql-bin.index drwx------ 2 mysql mysql 4096 Feb 21 14:17 performance_schema drwxr-xr-x 2 mysql mysql 4096 Feb 21 14:02 test |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 120 | +------------------+-----------+ 1 row in set (0.00 sec) mysql> mysql> show binlog events in "mysql-bin.000001" \G; *************************** 1. row *************************** Log_name: mysql-bin.000001 Pos: 4 Event_type: Format_desc Server_id: 1 End_log_pos: 120 Info: Server ver: 5.6.10-log, Binlog ver: 4 1 row in set (0.00 sec) ERROR: No query specified mysql> mysql> mysql> flush logs; Query OK, 0 rows affected (0.02 sec) mysql> mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 167 | | mysql-bin.000002 | 120 | +------------------+-----------+ 2 rows in set (0.00 sec) mysql> show binlog events in "mysql-bin.000001" \G; *************************** 1. row *************************** Log_name: mysql-bin.000001 Pos: 4 Event_type: Format_desc Server_id: 1 End_log_pos: 120 Info: Server ver: 5.6.10-log, Binlog ver: 4 *************************** 2. row *************************** Log_name: mysql-bin.000001 Pos: 120 Event_type: Rotate Server_id: 1 End_log_pos: 167 Info: mysql-bin.000002;pos=4 2 rows in set (0.00 sec) ERROR: No query specified mysql> mysql> show binlog events in "mysql-bin.000002" \G; *************************** 1. row *************************** Log_name: mysql-bin.000002 Pos: 4 Event_type: Format_desc Server_id: 1 End_log_pos: 120 Info: Server ver: 5.6.10-log, Binlog ver: 4 1 row in set (0.00 sec) ERROR: No query specified mysql> |
转载地址:http://sgfsa.baihongyu.com/