一.什么是二进制日志

1.记录对数据发生或潜在发生更改的sql语句

2.二进制格式保存

3.用途广泛,包括

a.查看数据库变更历史

b.数据库增量备份

c.数据库灾难恢复

d.mysql replication

二.不重启修改二进制日志配置

1.set @@global.log_bin=1;

2.set @@global.binlog_size=37268  (单位是bytes)

3.其他参数通过以下命令查阅

show variables like '%bin%';

三.常用二进制日志相关参数

修改以下配置后,需要重启数据库服务使其生效

1.log-bin=

开启并指定二进制日志的保存路径及文件名,不设置则使用默认值,默认存放位置为数据库文件所在目录下,名称为hostname-bin.xxxx

2.max-binlog-size=500m

设置单个二进制日志文件的最大值,默认为1G,最大也为1G

3.binlog-do-db与binlog-ignore-db

指定二进制日志文件记录那些数据库操作,不记录那些数据库操作

4.binlog-cache-size=100m

设置二进制日志缓存大小

5.sync-binlog=N

每隔N秒将缓存中的二进制日志记录写回硬盘,默认为0,不过,你经常会陷入group commit函数与I/O之间的二选一矛盾,如果在replication环境中,由于考虑到耐久性及一致性,则需设置为1,同时还需要设置innodb-flush-log-at-trx-commit=1 及 innodb-support-xa=1(默认已开启)

三.二进制的操作及总结

1.暂停二进制日志

set sql_log_bin = {0|1}

2.查看二进制日志

mysqlbinlog master-bin.000001

mysqlbinlog -v master-bin.000001

mysqlbinlog -v master-bin.000001 > test.sql       #导出二进制日志到sql脚本

mysqlbinlog -v master-bin.000001 >> test.sql     #追加二进制日志到sql脚本

3.mysqlbinlog的命令参数

  1. Usage: mysqlbinlog [options] log-files
  2. -?, --help Display this help and exit.
  3. --base64-output=name
  4. Determine when the output statements should be
  5. base64-encoded BINLOG statements: 'never' disables it and
  6. works only for binlogs without row-based events;
  7. 'decode-rows' decodes row events into commented
  8. pseudo-SQL statements if the --verbose option is also
  9. given; 'auto' prints base64 only when necessary (i.e.,
  10. for row-based events and format description events). If
  11. no --base64-output[=name] option is given at all, the
  12. default is 'auto'.
  13. --bind-address=name IP address to bind to.
  14. --character-sets-dir=name
  15. Directory for character set files.
  16. -d, --database=name List entries for just this database (local log only).
  17. --debug-check Check memory and open file usage at exit .
  18. --debug-info Print some debug info at exit.
  19. --default-auth=name Default authentication client-side plugin to use.
  20. -D, --disable-log-bin
  21. Disable binary log. This is useful, if you enabled
  22. --to-last-log and are sending the output to the same
  23. MySQL server. This way you could avoid an endless loop.
  24. You would also like to use it when restoring after a
  25. crash to avoid duplication of the statements you already
  26. have. NOTE: you will need a SUPER privilege to use this
  27. option.
  28. -F, --force-if-open Force if binlog was not closed properly.
  29. (Defaults to on; use --skip-force-if-open to disable.)
  30. -f, --force-read Force reading unknown binlog events.
  31. -H, --hexdump Augment output with hexadecimal and ASCII event dump.
  32. -h, --host=name Get the binlog from server.
  33. -l, --local-load=name
  34. Prepare local temporary files for LOAD DATA INFILE in the
  35. specified directory.
  36. -o, --offset=# Skip the first N entries.
  37. -p, --password[=name]
  38. Password to connect to remote server.
  39. --plugin-dir=name Directory for client-side plugins.
  40. -P, --port=# Port number to use for connection or 0 for default to, in
  41. order of preference, my.cnf, $MYSQL_TCP_PORT,
  42. /etc/services, built-in default (3306).
  43. --protocol=name The protocol to use for connection (tcp, socket, pipe,
  44. memory).
  45. -R, --read-from-remote-server
  46. Read binary logs from a MySQL server. This is an alias
  47. for read-from-remote-master=BINLOG-DUMP-NON-GTIDS.
  48. --read-from-remote-master=name
  49. Read binary logs from a MySQL server through the
  50. COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by
  51. setting the option to either BINLOG-DUMP-NON-GTIDS or
  52. BINLOG-DUMP-GTIDS, respectively. If
  53. --read-from-remote-master=BINLOG-DUMP-GTIDS is combined
  54. with --exclude-gtids, transactions can be filtered out on
  55. the master avoiding unnecessary network traffic.
  56. --raw Requires -R. Output raw binlog data instead of SQL
  57. statements, output is to log files.
  58. -r, --result-file=name
  59. Direct output to a given file. With --raw this is a
  60. prefix for the file names.
  61. --secure-auth Refuse client connecting to server if it uses old
  62. (pre-4.1.1) protocol.
  63. (Defaults to on; use --skip-secure-auth to disable.)
  64. --server-id=# Extract only binlog entries created by the server having
  65. the given id.
  66. --server-id-bits=# Set number of significant bits in server-id
  67. --set-charset=name Add 'SET NAMES character_set' to the output.
  68. -s, --short-form Just show regular queries: no extra info and no row-based
  69. events. This is for testing only, and should not be used
  70. in production systems. If you want to suppress
  71. base64-output, consider using --base64-output=never
  72. instead.
  73. -S, --socket=name The socket file to use for connection.
  74. --start-datetime=name
  75. Start reading the binlog at first event having a datetime
  76. equal or posterior to the argument; the argument must be
  77. a date and time in the local time zone, in any format
  78. accepted by the MySQL server for DATETIME and TIMESTAMP
  79. types, for example: 2004-12-25 11:25:56 (you should
  80. probably use quotes for your shell to set it properly).
  81. -j, --start-position=#
  82. Start reading the binlog at position N. Applies to the
  83. first binlog passed on the command line.
  84. --stop-datetime=name
  85. Stop reading the binlog at first event having a datetime
  86. equal or posterior to the argument; the argument must be
  87. a date and time in the local time zone, in any format
  88. accepted by the MySQL server for DATETIME and TIMESTAMP
  89. types, for example: 2004-12-25 11:25:56 (you should
  90. probably use quotes for your shell to set it properly).
  91. --stop-never Wait for more data from the server instead of stopping at
  92. the end of the last log. Implicitly sets --to-last-log
  93. but instead of stopping at the end of the last log it
  94. continues to wait till the server disconnects.
  95. --stop-never-slave-server-id=#
  96. The slave server_id used for --read-from-remote-server
  97. --stop-never.
  98. --stop-position=# Stop reading the binlog at position N. Applies to the
  99. last binlog passed on the command line.
  100. -t, --to-last-log Requires -R. Will not stop at the end of the requested
  101. binlog but rather continue printing until the end of the
  102. last binlog of the MySQL server. If you send the output
  103. to the same MySQL server, that may lead to an endless
  104. loop.
  105. -u, --user=name Connect to the remote server as username.
  106. -v, --verbose Reconstruct pseudo-SQL statements out of row events. -v
  107. -v adds comments on column data types.
  108. -V, --version Print version and exit.
  109. --open-files-limit=#
  110. Used to reserve file descriptors for use by this program.
  111. -c, --verify-binlog-checksum
  112. Verify checksum binlog events.
  113. --binlog-row-event-max-size=#
  114. The maximum size of a row-based binary log event in
  115. bytes. Rows will be grouped into events smaller than this
  116. size if possible. This value must be a multiple of 256.
  117. --skip-gtids Do not print Global Transaction Identifier information
  118. (SET GTID_NEXT=... etc).
  119. --include-gtids=name
  120. Print events whose Global Transaction Identifiers were
  121. provided.
  122. --exclude-gtids=name
  123. Print all events but those whose Global Transaction
  124. Identifiers were provided.

4.删除二进制日志

a.二进制日志会不断的增长,并产生多个文件,因此需要制定备份计划和管理策略,无用的二进制日志要记得及时删除

b.删除二进制日志有三种方法:

1.操作系统命令直接删除

2.reset master

3.purge

purge {master | binary} logs to 'log_name'

purge {master | binary} logs before 'date'

5.总结

a.日志影响mysql的性能有大量的磁盘空间,因此,往往做采样分析时才打开

b.即使做采样分析,也最好仅在一台测试机器上开启

c.二进制日志由于用途广泛,大多数情况下会开启,需要制定合理的备份计划和管理策略

mysql学习------二进制日志的更多相关文章

  1. mysql学习------二进制日志管理

    MySQL二进制日志(Binary Log)   a.它包含的内容及作用如下:    包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE)    包含关于每个更新数据库( ...

  2. 如何通过Mysql的二进制日志恢复数据库数据

    经常有网站管理员因为各种原因和操作,导致网站数据误删,而且又没有做网站备份,结果不知所措,甚至给网站运营和盈利带来负面影响.所以本文我们将和大家一起分享学习下如何通过Mysql的二机制日志(binlo ...

  3. MySQL使用二进制日志恢复数据库

    一.二进制日志简介 MySQL有不同类型的日志,其中二进制文件记录了所有对数据库的修改,如果数据库因为操作不当或其他原因丢失了数据,可以通过二进制文件恢复. 在my.ini文件中设置了log-bin, ...

  4. mysql删除二进制日志文件

    一.RESET MASTER 这个语句可以验证首次配置主机备机是否成功.步骤如下: 1. 启动master和 slave,开启replication (即 复制) 注:replication (复制) ...

  5. mysql使用二进制日志恢复数据

    一.恢复到某个二进制文件 1.开启二进制日志 在mysqld的配置节点下添加如下配置 log-bin="E:/Mysql57BinLog/binlog"(windows下的路径,l ...

  6. MYSQL使用二进制日志来恢复数据

    mysqlbinlog工具的使用,大家可以看MySQL的帮助手册.里面有详细的用, 在这个例子中,重点是--start-position参数和--stop-position参数的使用. ·--star ...

  7. Mysql清理二进制日志的技巧

    1:二进制日志 二进制日志记录了所有的DDL(数据定义语言)语句和DML(数据操作语言)语句,但是不记录包括数据查询的语句.语句以"事件"的形式保存,它描述了数据的更改过程,此日志 ...

  8. mysql学习------错误日志和通用查询日志

    一.启动错误日志 1.在不同情况下,错误日志会记录在不同的位置.如果没有在配置文件中指定文件名,则文件名默认为hostname.err 2.在mysql5.6的rpm发布方式中,错误的日志默认的放置在 ...

  9. Mysql binlog二进制日志

    Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的实际原sql语句都会被记录在binlog中. 优点:不需要记录每一 ...

随机推荐

  1. 基于python的机器学习实现日元币对人民币汇率预测

    ## 导入所需的包 import pandas as pd import numpy as np import matplotlib.pyplot as plt import tensorflow a ...

  2. TAC队--团队选题报告

    The Art of Code--团队选题报告 一个APP项目能否被大众所接受,能否拥有受众,the most important是它的idea. 一个好的idea可以为项目带来巨大的改变 一个 独特 ...

  3. 微软必应词典UWP -2017春

    必应UWP调研,评测 软件平台:windows10 软件名称:微软必应词典 软件类型:UWP Bug Bug1 当在文本框中进行输入时,在谷歌拼音输入法状态下,无法使用Shift键切换到谷歌拼音的纯英 ...

  4. [转帖]LNMP组件安装

    https://lnmp.org/install.html 系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian/Deepin/Aliyun/Amazon/M ...

  5. salt-api安装以及简单实使用

    1.安装说明 操作系统版本:CentOS Linux release 7.5.1804 (Core) saltstack版本:2018.3.2 已经关闭selinux.firewalld服务. 2.配 ...

  6. SpringBoot入坑指南之六:使用过滤器或拦截器

    在Web应用中,常常存在拦截全部或部分请求进行统一处理的应用场景,如权限校验.参数校验.性能监控等. 在SpringMVC框架中,我们可以通过过滤器或拦截器实现相关功能,spring-boot-sta ...

  7. 德国GG了

    我想起了今年ZJOI 这就是生活啊,伤悲总是要面对的

  8. Codeforces 468C/469E 易错点

    #include <stdio.h> #include <stdlib.h> typedef long long ll; int main() { ll x=1e17; ll ...

  9. arcgis创建渔网

    创建渔网 1.     ArcToolbox > Data Management Tools > Feature Class > Create Finshnet.选择输出要素位置,模 ...

  10. arcgis计算邻接矩阵

    求邻接矩阵 教程链接   http://m.blog.csdn.net/wan_yanyan528/article/details/49175673 (1) 将目标shp文件导出一份副本备用(以省级为 ...