How MySQL data file corruption is restored to its latest state

Source: Internet
Author: User
Tags create database

Preparation Environment:

< Span style= "box-sizing:border-box;padding-right:0.1px" > two hosts:  
a:192.168.1.6   data corruption
b:192.168.1.7   data recovery

Build steps:

Host A (192.168.1.6):

    • full backup database

< Span style= "box-sizing:border-box;padding-right:0.1px" >mysqldump-a-F--single-transaction--master-data=1 >/ Backup/fullbak ' Date +%f '. SQL  

labeled red Location is the latest generated new binaries and locations (all previous backups) after a full backup for binary log recovery

    • Modify Database

< Span style= "box-sizing:border-box;padding-right:0.1px" >mysql> create database db1;  
mysql> CREATE database DB2;
    • simulation data file corruption

< Span style= "box-sizing:border-box;padding-right:0.1px" ># rm-rf/var/lib/mysql/*  
    • close database

< Span style= "box-sizing:border-box;padding-right:0.1px" >systemctl stop mariadb  
    • backup binary log

< Span style= "box-sizing:border-box;padding-right:0.1px" >mysqlbinlog--start-position=245 mariadb-bin.000002 >/ Backup/bin.sql  
    • Copy the backup log to Host B

< Span style= "box-sizing:border-box;padding-right:0.1px" >scp/backup/fullbak2018-06-16.sql/backup/bin.sql   192.168.1.7:/root/ 


Host B (192.168.1.7):

    • Turn off network snooping

< Span style= "box-sizing:border-box;padding-right:0.1px" >vim/etc/my.cnf  
[mysqld]
Skip_networking
    • Open database

< Span style= "box-sizing:border-box;padding-right:0.1px" >systemctl start mariadb  
    • recover data

< Span style= "box-sizing:border-box;padding-right:0.1px" >mysql </root/fullbak2018-06-16.sql     Full backup recovery 
    
mysql </root/bin.sql                   binary log recovery



How MySQL data file corruption is restored to its latest state

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.