• 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.
  • 相关阅读:
    面试题 08.02. 迷路的机器人(C++)
    URI和URL的区别
    Kali Linux自定义分辨率设置
    CentOS最小化安装后配置NAT网络模式
    CentOS7.5安装及最小安装后联网配置--联网配置
    CentOS7.5安装及最小安装后联网配置--系统安装
    基数排序
    归并排序
    堆排序
    简单选择排序
  • 原文地址:https://www.cnblogs.com/iLoveMyD/p/2555677.html
Copyright © 2020-2023  润新知