当前位置:   article > 正文

MySQL使用MariaDB的binlog闪回_mariadb mysqlbilong flashback

mariadb mysqlbilong flashback
  1. 原文: https://www.yuque.com/wei01/wql35u/xcig4l
  2. 8.0之前应该都支持
  3. 解压mariadb安装包:
  4. tar xvf mariadb-10.4.20-linux-x86_64.tar.gz
  5. 模拟误删除
  6. session 1:
  7. mysqlslap -a -uroot -proot1234 -c 50 -i 100
  8. mysqlslap: [Warning] Using a password on the command line interface can be insecure.
  9. session 2
  10. delete from tr;
  11. Query OK, 10000 rows affected (2.45 sec)
  12. 解析binlog, 找到误删时间点
  13. /root/mariadb-10.4.20-linux-x86_64/bin/mysqlbinlog -uroot -proot1234 --database=test --table=tr -vv --base64-output=DECODE-ROWS mysql-bin.000017 --start-datetime '2021-07-08 14:11:00'> /tmp/raw.sql
  14. #210708 14:11:28 server id 24750 end_log_pos 47123213 CRC32 0xd76755ff Ignorable
  15. # Ignorable event type 29 (MySQL Rows_query)
  16. # at 47123213
  17. #210708 14:11:28 server id 24750 end_log_pos 47123262 CRC32 0xd9e8559c Table_map: `test`.`tr` mapped to number 964
  18. # at 47123262
  19. # at 47131469
  20. # at 47139676
  21. # at 47147883
  22. # at 47156090
  23. # at 47164297
  24. # at 47172504
  25. # at 47180711
  26. # at 47188918
  27. # at 47197125
  28. # at 47205332
  29. # at 47213539
  30. #210708 14:11:28 server id 24750 end_log_pos 47131469 CRC32 0x50535c4b Delete_rows: table id 964
  31. #210708 14:11:28 server id 24750 end_log_pos 47139676 CRC32 0x9f9f77b2 Delete_rows: table id 964
  32. #210708 14:11:28 server id 24750 end_log_pos 47147883 CRC32 0x59eeedaa Delete_rows: table id 964
  33. #210708 14:11:28 server id 24750 end_log_pos 47156090 CRC32 0xdb0a684a Delete_rows: table id 964
  34. #210708 14:11:28 server id 24750 end_log_pos 47164297 CRC32 0xdf79875c Delete_rows: table id 964
  35. #210708 14:11:28 server id 24750 end_log_pos 47172504 CRC32 0x2e1e01b9 Delete_rows: table id 964
  36. #210708 14:11:28 server id 24750 end_log_pos 47180711 CRC32 0xcff83af6 Delete_rows: table id 964
  37. #210708 14:11:28 server id 24750 end_log_pos 47188918 CRC32 0x0987243a Delete_rows: table id 964
  38. #210708 14:11:28 server id 24750 end_log_pos 47197125 CRC32 0xe145a0a2 Delete_rows: table id 964
  39. #210708 14:11:28 server id 24750 end_log_pos 47205332 CRC32 0x1169c490 Delete_rows: table id 964
  40. #210708 14:11:28 server id 24750 end_log_pos 47213539 CRC32 0x483cb228 Delete_rows: table id 964
  41. #210708 14:11:28 server id 24750 end_log_pos 47213682 CRC32 0x735d8aca Delete_rows: table id 964 flags: STMT_END_F
  42. ### DELETE FROM `test`.`tr`
  43. ...
  44. ### @2=993 /* INT meta=0 nullable=1 is_null=0 */
  45. ### @3=NULL /* VARSTRING(30) meta=30 nullable=1 is_null=1 */
  46. ### DELETE FROM `test`.`tr`
  47. ### WHERE
  48. ### @1=10000 /* INT meta=0 nullable=0 is_null=0 */
  49. ### @2=516 /* INT meta=0 nullable=1 is_null=0 */
  50. ### @3=NULL /* VARSTRING(30) meta=30 nullable=1 is_null=1 */
  51. # Number of rows: 10000
  52. # at 47213682
  53. #210708 14:11:28 server id 24750 end_log_pos 47213713 CRC32 0xcd8993e2 Xid = 146956
  54. COMMIT/*!*/;
  55. 生成闪回语句
  56. /root/mariadb-10.4.20-linux-x86_64/bin/mysqlbinlog --flashback -uroot -proot1234 --database=test --table=tr --start-position=47123213 --stop-position=47213682 mysql-bin.000017 > /tmp/flash.sql
  57. 由于开启GTID所以报错,建议先恢复到一个临时环境,然后再导入到生产环境
  58. [root@mysql1 binlog]# mysql</tmp/flash.sql
  59. ERROR 1782 (HY000) at line 28: @@SESSION.GTID_NEXT cannot be set to ANONYMOUS when @@GLOBAL.GTID_MODE = ON.
  60. [root@mysql1 binlog]# mysql</tmp/flash.sql
  61. [root@mysql1 binlog]# mysql
  62. Welcome to the MySQL monitor. Commands end with ; or \g.
  63. Your MySQL connection id is 9848
  64. Server version: 5.7.27-log MySQL Community Server (GPL)
  65. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  66. Oracle is a registered trademark of Oracle Corporation and/or its
  67. affiliates. Other names may be trademarks of their respective
  68. owners.
  69. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  70. [root@localhost][(none)]: use test;
  71. Database changed
  72. [root@localhost][test]: select count(*) from tr;
  73. +----------+
  74. | count(*) |
  75. +----------+
  76. | 10000 |
  77. +----------+
  78. 1 row in set (0.01 sec)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/955282
推荐阅读
相关标签
  

闽ICP备14008679号