个人技术分享

binlog 

binlog   单个大小默认1G,超过了1G就会新增一个
mysql   重启一次就会增加一个新的

查看

show binary logs;

show binary log status;

show variables like 'max_binlog_size';

过期

默认存30天,以秒计

show variables like 'binlog_expire_logs_seconds';

show variables like '%log_bin_basename%';

清理

手工设置10天

set global binlog_expire_logs_seconds  = 864000;

flush logs;

恢复误删除

eg:

mysql> select * from ceshi;
+------+------+
| id   | name |
+------+------+
|    1 | t    |
|    2 | y    |
|    3 | r    |
+------+------+
3 rows in set (0.01 sec)

mysql> delete from ceshi where id = 3;
Query OK, 1 row affected (0.00 sec)

mysql> select * from ceshi;
+------+------+
| id   | name |
+------+------+
|    1 | t    |
|    2 | y    |
+------+------+
2 rows in set (0.00 sec)

mysql> 

查看mysql正在使用的binlog日志文件
mysql> show binary logs;
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000010 |       446 | No        |
+---------------+-----------+-----------+
1 row in set (0.00 sec)

查找start-position和stop-position的位置

mysqlbinlog -uroot -proot    --verbose  /var/lib/mysql/data/binlog.000010 | grep -iC 200 'delete from'

恢复要卡住一个start-position和stop-position的位置区间

mysqlbinlog -uroot -proot  --start-position=525  --stop-position=734 /var/lib/mysql/data/binlog.000010 | mysql -uroot -proot

恢复查看

mysql> select * from ceshi;
+------+------+
| id   | name |
+------+------+
|    1 | t    |
|    2 | y    |
|    3 | r    |
+------+------+
3 rows in set (0.00 sec)