zoukankan      html  css  js  c++  java
  • MySQL5.7开启binlog日志,及数据恢复简单示例

      1、相关命令

      1)查看是否开启 binlog日志(默认不开启,log_bin值为OF)及日志位置

      show variables like '%log_bin%';

      

      2)查看产生的 日志文件。

      show binary logs;

      3)查看当前使用的日志文件,即记录操作的最后一个日志文件

      show master status;

      4)查看日志事件信息 ,开始、结束操作位置等

      show binlog events;

      5)查看mysql-bin.000001日志文件的事件信息 ,开始、结束操作位置等

      show binlog events in 'mysql-bin.000001';

      6)产生新日志,后面的操作会写到新日志中,日志名mysql-bin.00000X+1

      flush logs;

      7)清空所有的日志,从mysql-bin.000001开始重新记录日志

      reset master;

      8)查询mysql-bin.000001中记录的操作,不显示sql,要进入到mysql的安装目录中

      mysqlbinlog mysql-bin.000001;

      9)查询mysql-bin.000001中记录的操作,会显示sql语句

      mysqlbinlog --base64-output=decode-rows -v mysql-bin.000001;

      2、开启binlog

      修改配置文件/etc/my.cnf,增加如下配置:

    log_bin=mysql-bin  
    server-id = 1

      说明:

      1)看准log_bin是下划线,不是横杠,mysql-bin是定义的 产生日志的文件名前缀。

      2)server-id的值随便指定 ,集群环境下不能重复。

      3)配置完成后,需要重启数据库,此时/var/lib/mysql下已经产生日志文件mysql-bin.index、mysql-bin.000001

      3、演示数据恢复

      1)查看当前日志文件

      

      当前记录日志文件mysql-bin.000001,初始位置154。 

      2)新建数据库mydb1,新建表t_test1,并准备数据如下

      

       3)再次查看记录位置,发现记录位置已改变

      

      4) 查看mysql-bin.000001日志文件的事件信息 ,开始、结束操作位置等

      

      

      5)查看记录日志的详细信息,可以看到sql语句

      

      

      6)重新开启新日志

      

      7)开始演示恢复表操作,首先删除表 

      

      8)查看建表位置

    [root@localhost mysql]# mysqlbinlog --base64-output=decode-rows -v mysql-bin.000001;

      

      9)执行恢复语句,查询结果,表及数据恢复完成。

      

      

      备注:本篇主要目的是演示binlog的相关命令,其中数据恢复的例子单纯为了演示,实际工作中要复杂的多,相关文章请参考后面的文章。

       

      

  • 相关阅读:
    Begin Example with Override Encoded SOAP XML Serialization
    State Machine Terminology
    How to: Specify an Alternate Element Name for an XML Stream
    How to: Publish Metadata for a WCF Service.(What is the Metadata Exchange Endpoint purpose.)
    Beginning Guide With Controlling XML Serialization Using Attributes(XmlSerializaiton of Array)
    Workflow 4.0 Hosting Extensions
    What can we do in the CacheMetaData Method of Activity
    How and Why to use the System.servicemodel.MessageParameterAttribute in WCF
    How to: Begin Sample with Serialization and Deserialization an Object
    A Test WCF Service without anything of config.
  • 原文地址:https://www.cnblogs.com/javasl/p/13043971.html
Copyright © 2011-2022 走看看