zoukankan      html  css  js  c++  java
  • mysql 利用二进制日志进行数据恢复(mysqlbinlog)

    老大让在windows下安装mysql服务(mysql免安装版http://download.softagency.net/MySQL/Downloads/MySQL-5.1/

    查看当前正在写的日志文件:mysql show master status 

    mysql> show master status;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000002 |      907 |              |                  |
    +------------------+----------+--------------+------------------+

    用mysqlbinlog命令导出可理解的文本文档:(两句都一样,下边的-r是--result-file参数的别名)

    D:\mysql5163\data>mysqlbinlog --result-file=D:/result2.txt mysql-bin.000002
    
    D:\mysql5163\data>mysqlbinlog -rD:/result2.txt mysql-bin.000002

    用记事本打开result2.txt

    # at 221
    #120619 16:06:00 server id 1  end_log_pos 323     Query    thread_id=1    exec_time=0    error_code=0
    SET TIMESTAMP=1340093160/*!*/;
    insert into test value(1,12,'zhangsan')
    /*!*/;
    # at 323
    #120619 16:26:13 server id 1  end_log_pos 421     Query    thread_id=1    exec_time=0    error_code=0
    SET TIMESTAMP=1340094373/*!*/;
    insert into test value(2,12,'lisi')
    /*!*/;

    按位置恢复(按日期恢复时,老提示我日期有错误,不合格)第一条:

    D:\mysql5163\data>mysqlbinlog --start-position=221 --stop-position=323 mysql-bin.000002 | mysql -uroot

    注意:1.恢复一条时用这一条的两边的两个at后的值(#at 221 #at 323)当然 也可以用相应的end_log_pos来定位某条语句或某几条语句

    2.参数和命令跟 Linux下一样(mysqlbinlog -help)

    3.我的二进制日志存放在数据库目录下(默认的路径),我的mysqlbinlog 命令是在日志文件的目录下敲的,如果你不是的话可以将目录补全

     找到了,实验成功:通过日期进行恢复,使用的是双引号http://www.cnblogs.com/xionghui/archive/2012/03/11/2389792.html

    >mysqlbinlog --start-datetime="2009-09-14 0:20:00" --stop-datetim="2009-09-15 01:25:00" /diskb/bin-logs/xxx_db-bin.000001 | mysql -u root

    ps:命令帮助

     --start-datetime=name
                         Start reading the binlog at first event having a datetime
                         equal or posterior to the argument; the argument must be
                         a date and time in the local time zone, in any format  //任何mysql能接收的日期格式
                         accepted by the MySQL server for DATETIME and TIMESTAMP
                         types, for example: 2004-12-25 11:25:56 (you should
                         probably use quotes for your shell to set it properly). //最好用引号(双引号)
     -j, --start-position=#
                         Start reading the binlog at position N. Applies to the
                         first binlog passed on the command line.
  • 相关阅读:
    <转>lua 调用 C函数
    <转>VC之获取CPU序列号
    <转> 求结构体偏移
    借助 FireBug 进行轻量级代码自动生成。
    内存盘配置IIS临时目录
    导出带有复合表头的Excel方案.
    左右互博之精简代码
    [转]JavaScript 秘密花园
    MVC中,Ajax Post 数组的实现方案
    Sql 存储过程 参数传递空字符串, 到SQL 端变成了 空格!!
  • 原文地址:https://www.cnblogs.com/iLoveMyD/p/2555677.html
Copyright © 2011-2022 走看看