mysql-binlog日志说明、备份、恢复数据
一、开启binlog日志功能
[root@localhost ~]# vim /etc/my.cnf
#`在[mysqld] 区块添加`
log-bin=mysql-bin #确认是打开状态(mysql-bin 是日志的基本名或前缀名)
#binlog-ignore-db=mysql #忽略数据库(被忽略的数据库中,二进制文件中是无记录的!)
- 注意:每次服务器(数据库)重启,服务器会调用flush logs;,新创建一个binlog日志!
1.查看所有二进制日志文件
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 120 |
+------------------+-----------+
1 row in set (0.00 sec)
2.查看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 | 128 | 120 | Server ver: 5.6.43-log, Binlog ver: 4 |
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
1 row in set (0.00 sec)
3.查看binlog日志是否开启
mysql> show variables like 'log_%';
+----------------------------------------+-----------------------------+
| Variable_name | Value |
+----------------------------------------+-----------------------------+
| log_bin | ON |
| log_bin_basename | /data/mysql/mysql-bin |
| log_bin_index | /data/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| log_error | ./localhost.localdomain.err |
.........
+----------------------------------------+-----------------------------+
13 rows in set (0.00 sec)
二、常用的binlog日志操作命令
1.查看所有binlog日志列表
mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 120 |
+------------------+-----------+
1 row in set (0.00 sec)
2.查看最新master状态
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------