MySQL的binlog操作
1. MySQL的binlog有三种模式: statement, row and mixed, 从5.1开始支持row, 默认是row模式
2. 设置参数
# 要配置在mysqld下
[mysqld]
binlog_format=ROW
设置binlog过期清理时间 expire_logs_days
# Should be unique
server-id =
log-bin = master-bin
# The number of days for automatic binary log file removal
expire_logs_days =
# :log&flush per 1s; :log&flush per commit; :log per commit & flush per 1s
innodb_flush_log_at_trx_commit=
# The number of binary log commit groups to collect before sync to disk.
sync_binlog =
3. 查看binlog是否开启及其参数
mysql> show variables like 'log_bin%';
+---------------------------------+---------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/master-bin |
| log_bin_index | /var/lib/mysql/master-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+---------------------------------+
5 rows in set (0.01 sec) mysql> show variables like 'binlog%';
+-----------------------------------------+--------------+
| Variable_name | Value |
+-----------------------------------------+--------------+
| binlog_cache_size | 32768 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
+-----------------------------------------+--------------+
13 rows in set (0.00 sec)
4. 查看服务器的binlog状态
mysql> show binary logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin.000008 | 321270 |
| master-bin.000009 | 1026 |
| master-bin.000010 | 10103 |
| master-bin.000011 | 544150473 |
| master-bin.000012 | 4155620 |
| master-bin.000013 | 21550593 |
+-------------------+-----------+
6 rows in set (0.00 sec) mysql> show master logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin.000008 | 321270 |
| master-bin.000009 | 1026 |
| master-bin.000010 | 10103 |
| master-bin.000011 | 544150473 |
| master-bin.000012 | 4155620 |
| master-bin.000013 | 21550593 |
+-------------------+-----------+
6 rows in set (0.00 sec) mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000013 | 21551221 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
5. 查看binlog内容
# 查看指定binlog文件的内容语法:
SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]
例如
mysql> show binlog events limit 0, 5;
+-------------------+-----+----------------+-----------+-------------+------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+----------------+-----------+-------------+------------------------------------------+
| master-bin.000008 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.14-log, Binlog ver: 4 |
| master-bin.000008 | 123 | Previous_gtids | 1 | 154 | |
| master-bin.000008 | 154 | Anonymous_Gtid | 1 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| master-bin.000008 | 219 | Query | 1 | 290 | BEGIN |
| master-bin.000008 | 290 | Query | 1 | 385 | use `yic`; DELETE FROM `yic`.`u_session` |
+-------------------+-----+----------------+-----------+-------------+------------------------------------------+
5 rows in set (0.00 sec)
mysql> show binlog events in 'master-bin.000013' limit 0, 5;
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| master-bin.000013 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.14-log, Binlog ver: 4 |
| master-bin.000013 | 123 | Previous_gtids | 1 | 154 | |
| master-bin.000013 | 154 | Anonymous_Gtid | 1 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| master-bin.000013 | 219 | Query | 1 | 290 | BEGIN |
| master-bin.000013 | 290 | Table_map | 1 | 373 | table_id: 111 (yic.u_session_log) |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
5 rows in set (0.00 sec)
注意: 都是按时间正序排列.
6. 使用mysqlbinlog查看binlog
# 提取指定的binlog日志 (参数需要用绝对路径)
mysqlbinlog /opt/data/APP01bin.
# 根据位置提取
mysqlbinlog --start-position="" --stop-position="" /opt/data/APP01bin.
# 根据开始结束时间提取
mysqlbinlog --start-datetime="2014-12-15 20:15:23" --stop-datetime="2014-12-15 20:30:23" /opt/data/APP01bin. --result-file=extra02.sql
# 对多个binlog文件, 提取指定数据库, 并转换字符集
mysqlbinlog --database=test --set-charset=utf8 /opt/data/APP01bin. /opt/data/APP01bin. >test.sql
# 提取远程的binlog, 并输出到本地
mysqlbinlog -u someone -p -P3306 -h192.168.1. --read-from-remote-server -vv inst3606bin. >row.sql
mysqlbinlog 查看row模式的binlog
# 使用--base64-output=decode-rows -v参数, 就能看懂了
mysqlbinlog --base64-output=decode-rows -v /var/lib/mysql/master-bin.|more
MySQL的binlog操作的更多相关文章
- MySQL 利用SQL线程对Binlog操作
背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...
- MySQL 利用SQL线程对Binlog操作(转)
背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...
- Mysql之binlog日志说明及利用binlog日志恢复数据操作记录
众所周知,binlog日志对于mysql数据库来说是十分重要的.在数据丢失的紧急情况下,我们往往会想到用binlog日志功能进行数据恢复(定时全备份+binlog日志恢复增量数据部分),化险为夷! 一 ...
- mysql关于binlog日志的操作
查看binlog日志选项和存储位置: mysql> show variables like 'log_%'; 1.查看所有binlog日志列表 mysql> show master log ...
- Mysql使用binlog恢复数据解决误操作问题的两种方法
为保证没有其他参数配置影响,重新安装配置了一台最小化安装的CentOS7虚拟机 1. 基础知识 安装mysql5.6数据库Mysql binlog初步理解 2. 配置mysql 开启binlog.修 ...
- Mysql利用binlog日志恢复数据操作(转)
a.开启binlog日志:1)编辑打开mysql配置文件/etc/mys.cnf[root@vm-002 ~]# vim /etc/my.cnf在[mysqld] 区块添加 log-bin=mysql ...
- 【转】Mysql之binlog日志说明及利用binlog日志恢复数据操作记录
众所周知,binlog日志对于mysql数据库来说是十分重要的.在数据丢失的紧急情况下,我们往往会想到用binlog日志功能进行数据恢复(定时全备份+binlog日志恢复增量数据部分),化险为夷! 废 ...
- 【转】【MySQL】mysql 通过bin-log恢复数据方法详解
mysql中bin-log在mysql默认状态下是没有打开的,我们要先打开mysql 开启bin-log功能,然后再通过备份的bin-log进行数据库恢复了. 具体的操作是通过mysqlbinlog这 ...
- MySQL的binlog数据如何查看
binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...
随机推荐
- 奇怪吸引子---Chua
奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...
- 混沌分形之迭代函数系统(IFS)
IFS是分形的重要分支.它是分形图像处理中最富生命力而且最具有广阔应用前景的领域之一.这一工作最早可以追溯到Hutchinson于1981年对自相似集的研究.美国科学家M.F.Barnsley于198 ...
- C# 6.0 的那些事
这两天期中考试没时间去看Connect();直播,挺可惜的,考完后补看了Connect(); 把C#6.0的新东西总结一下. 自动属性初始化 (Initializers for auto-proper ...
- 文本分类(六):使用fastText对文本进行分类--小插曲
http://blog.csdn.net/lxg0807/article/details/52960072 环境说明:python2.7.linux 自己打自己脸,目前官方的包只能在linux,mac ...
- IIS配置中出现HRESULT:0X80070020错误
Win7 IIS启动失败.手工启动它,提示:“另一个程序正在使用此文件,进程无法访问!” 此时是因为另一个程序占用了IIS的端口号,IIS一般用的是80端口,是谁占用了这个端口呢? 方法如下:开始菜单 ...
- 如何实现Linux+Windows双系统启动
设置你的计算机根据需要启动 Windows 10 或 Ubuntu 18.04. 尽管 Linux 是一个有着广泛的硬件和软件支持的操作系统,但事实上有时你仍需要使用 Windows,也许是因为有些不 ...
- nova network工作原理及配置
1. nova network简介 网络管理和配置是云计算中一项非常重要的功能.nova自带的nova-network实现了一些基本的网络模型,允许虚拟机之间的相互通信及虚拟机对internet的访问 ...
- FastDFS tracker storage 的工作原理及流程
FastDFS tracker storage 的工作原理及流程 2013 年 3 月 11 日 – 09:22 | 1,409 views | 收藏 (No Ratings Yet) FastDF ...
- SDE操作的许可问题
ArcGIS二次开发和ArcGIS桌面应用中,许可是一个老生常谈的问题.以前也小结过一些经验.参考: http://www.cnblogs.com/liweis/p/4185311.html 问题描述 ...
- 面试小结之Elasticsearch篇
https://www.cnblogs.com/luckcs/articles/7052932.html