MySQL database InnoDB engine server power outage data recovery method

  • 2020-12-22 17:48:30
  • OfStack

Description:

One MySQL database server on the line suddenly lost power, which caused system failure and could not be started. After reinstalling the system, I found the previous MySQL database folder.

Question:

The previous MySQL database was restored by copying files, and it was found that the table in the database could not be found when the program was called, resulting in the website could not be accessed normally.

Analysis:

1. MySQL database, using copy file to restore the database, only supports MyISAM engine;
2. If any database or data table uses THE InnoDB engine, it must be copied together with the ibdata1 file in the MySQL database directory.

Solutions:

1. Stop the MySQL service

service mysqld stop

2. Find the previous backup database file

cd /home/mysql_bak/mysql/ # go to the MySQL backup directory

ibdata1 # requires this file

3. Copy ibdata1 file to the corresponding directory of the database

cp/home/mysql_bak/mysql/ibdata1 / usr/local/mysql/data/ibdata1 # copy files to the database directory
chown mysql. mysql usr/local/mysql/data/ibdata1 # set permissions mysql users and user groups
rm/usr/local/mysql data/ib_logfile0 # delete existing log files, or start MySQL failure
rm/usr/local/mysql data/ib_logfile1 # delete existing log files, or start MySQL failure


4. Start MySQL

service mysqld start

Failure to solve

At this point the page has opened normally.

ibdata1 is used for table data files under the InnoDB engine.

Recommendation: Database 1 must do a good backup, restore the data had better use.sql backup file import.

So far, MySQL database InnoDB engine under the server power outage data recovery tutorial completed.


Related articles: