zoukankan      html  css  js  c++  java
  • mysql binlog

    1.  开启
      //mysqld.cnf
      server-id               = 1
      log_bin                 = /var/log/mysql/mysql-bin.log
    2. 查询最新的日志
      mysql> show master status;
      +------------------+----------+--------------+------------------+-------------------+
      | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
      +------------------+----------+--------------+------------------+-------------------+
      | mysql-bin.000002 |     1053 |              |                  |                   |
      +------------------+----------+--------------+------------------+-------------------+
      1 row in set (0.01 sec)
    3. 写入,会生成一个最新的日志
      mysql> flush logs;
      Query OK, 0 rows affected (0.02 sec)
    4. 清空
      mysql> reset master;
      Query OK, 0 rows affected (0.08 sec)
      
      mysql> show master status;
      +------------------+----------+--------------+------------------+-------------------+
      | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
      +------------------+----------+--------------+------------------+-------------------+
      | mysql-bin.000001 |      154 |              |                  |                   |
      +------------------+----------+--------------+------------------+-------------------+
      1 row in set (0.01 sec)
    5. 查看binlog日志(row模式)
      sudo mysqlbinlog /var/log/mysql/mysql-bin.000003 --base64-output=decode-rows -v|more
      
      # at 339
      #190514  0:56:40 server id 1  end_log_pos 385 CRC32 0xc5bc8e18     Delete_rows: table id 108 fla
      gs: STMT_END_F
      ### DELETE FROM `test`.`t1`
      ### WHERE
      ###   @1=4
      ###   @2='Doken'
      # at 385
      #190514  0:56:40 server id 1  end_log_pos 416 CRC32 0xf0631419     Xid = 56
      COMMIT/*!*/;
      SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
      DELIMITER ;
      # End of log file
    6. 恢复数据
      sudo mysqlbinlog /var/log/mysql/mysql-bin.000003 | mysql -uroot -p test

      sudo mysqlbinlog -D --stop-position=2133 /var/log/mysql/mysql-bin.000001 | mysql -uroot -p
      // 从sql恢复
      // -v view
      // -f force 发生错误继续执行
      sudo mysql -uroot -p db_name -v -f < bak.sql
  • 相关阅读:
    GitLab 介绍
    git 标签
    git 分支
    git 仓库 撤销提交 git reset and 查看本地历史操作 git reflog
    git 仓库 回退功能 git checkout
    python 并发编程 多进程 练习题
    git 命令 查看历史提交 git log
    git 命令 git diff 查看 Git 区域文件的具体改动
    POJ 2608
    POJ 2610
  • 原文地址:https://www.cnblogs.com/fenle/p/10860027.html
Copyright © 2011-2022 走看看