MySQL数据库InnoDB引擎数据表的恢复示例
保持数据的完整性和一致性(Integrity and consistency)是数据库在商务应用中的核心内容,MySQL数据库使用InnoDB引擎来实现事务
保持数据的完整性和一致性(Integrity and consistency)是数据库在商务应用中的核心内容,MySQL数据库使用InnoDB引擎来实现事务处理(transaction),因此针对使用 InnoDB 类型引擎的数据表就需要有有更多检查和限制。而相应地,这也就更容易出现因为数据一致性和完整性而导致无法正常读取表中部分数据甚至全部记录的问题,因此在实际应用之中,您有可能需要比较多地面对如何恢复 InnoDB 数据表的问题。
本文笔记一次 InnoDB 数据表恢复的过程。
另外,值得一提的是,从MySQL 5.5.5 版本开始,预设引擎已经改为InnoDB了。
Starting from MySQL 5.5.5, the default storage engine for new tables is InnoDB.
(1) Get backup files(取得相关备份文件):
Data File: /var/lib/mysql/ibdata1
Logs File: /var/lib/mysql/ib_logfile0
Logs File: /var/lib/mysql/ib_logfile1
Database: bizness
Table Name: transaction
Table File: /var/lib/mysql/bizness/transaction.frm
(2) Setup temporary mysql service for recover(设置临时数据库以供恢复操作)
Create database and InnoDB table with same name engine(not matter the field name):
mysql> CREATE DATABASE bizness;
mysql> CREATE TABLE transaction(a INT) ENGINE=InnoDB;
Stop the temporary mysql service, and copy all the backup files to replace the
current databases files.(ibdata1,ib_logfile0,ib_logfile1,transaction.frm)
# cp -p ibdata1 /var/lib/mysql/
# cp -p ib_logfile0 /var/lib/mysql/
# cp -p ib_logfile1 /var/lib/mysql/
# cp -p transaction.frm /var/lib/mysql/bizness/
# chown mysql:mysql /var/lib/mysql/ibdata
# chown mysql:mysql /var/lib/mysql/ib_logfile0
# chown mysql:mysql /var/lib/mysql/ib_logfile1
# chown mysql:mysql /var/lib/mysql/transaction.frm
(3) Check the old logfiles size:
# /bin/ls -l -b /var/lib/mysql/ib_logfile*;
------------------------------------------------------------------------------
-rw-rw---- 1 mysql mysql 5242880 9月 2 13:29 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 7月 30 13:46 ib_logfile1
------------------------------------------------------------------------------
Note: the size is 5242880 bytes.
(4) Now start up mysql in rescue mode
# /usr/libexec/mysqld --innodb-log-file-size=5242880 --innodb-force-recovery=6
------------------------------------------------------------------------------
InnoDB: Initializing buffer pool, size = 8.0M
InnoDB: Completed initialization of buffer pool
InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
InnoDB: Skipping log redo
InnoDB: Started; log sequence number 0 0
InnoDB: !!! innodb_force_recovery is set to 6 !!!
[Note] Event Scheduler: Loaded 0 events
[Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
------------------------------------------------------------------------------
And then dump the database to SQL file with mysqldump command:
# mysqldump -u root -p bizness > bizness.sql
或者:
# mysqldump -u root -p bizness transaction > bizness.transaction.sql
如果成功导出了数据文本,那么就可以它用来进行恢复了,根据您所遇到的实际情况,,
您或许有可能需要现删除已经崩溃的数据表,然后再导入恢复出来的SQL文本。例如:
# mysql -u root -p bizness 或者:
# mysql -u root -p bizness
Note: mysql importing do not need to indicate the table name .
如有需要,可查看帮助说明:
# /usr/libexec/mysqld --verbose --help
--innodb-log-file-size=#
Size of each log file in a log group.
--innodb-force-recovery=#
Helps to save your data in case the disk image of the database becomes corrupt.
0 by default (normal startup without forced recovery)
官方网站的参考文档:
1 (SRV_FORCE_IGNORE_CORRUPT)
即使发现了损坏页也继续让服务运行,这个选项对于备份或者转存当前数据尤为有用。
Lets the server run even if it detects a corrupt page. Tries to make SELECT * FROM tbl_name
jump over corrupt index records and pages, which helps in dumping tables.
2 (SRV_FORCE_NO_BACKGROUND)
防止主线程和任何清除线程运行,如果清除操作会导致服务器挂掉,此选项有助于防止它。
Prevents the master thread and any purge threads from running. If a crash
would occur during the purge operation, this recovery value prevents it.
3 (SRV_FORCE_NO_TRX_UNDO)
恢复后不回滚事务。
Does not run transaction rollbacks after crash recovery.
4 (SRV_FORCE_NO_IBUF_MERGE)
如果插入到缓冲区的合并操作会导致系统崩溃,那么插入将不会被执行。
Prevents insert buffer merge operations. If they would cause a crash,
does not do them. Does not calculate table statistics.
5 (SRV_FORCE_NO_UNDO_LOG_SCAN)
启动数据库时,忽略撤消日志,InnoDB将未完成事务当作已经完成。
Does not look at undo logs when starting the database:
InnoDB treats even incomplete transactions as committed.
6 (SRV_FORCE_NO_LOG_REDO)
启动数据库时,忽略与恢复相关的前滚日志。
Does not do the redo log roll-forward in connection with recovery.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB adopts a dual-track authorization system, one is GPL authorization and the other is proprietary software authorization. InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID); InnoDB supports row-level locks, which can support concurrency to the greatest extent. Row-level locks are implemented by the storage engine layer.

InnoDB is a storage engine that stores data in tables on disk, so our data will still exist even after shutdown and restart. The actual process of processing data occurs in memory, so the data in the disk needs to be loaded into the memory. If it is processing a write or modification request, the contents in the memory also need to be refreshed to the disk. And we know that the speed of reading and writing to disk is very slow, which is several orders of magnitude different from reading and writing in memory. So when we want to get certain records from the table, does the InnoDB storage engine need to read the records from the disk one by one? The method adopted by InnoDB is to divide the data into several pages, and use pages as the basic unit of interaction between disk and memory. The size of a page in InnoDB is generally 16

1. Roll back and reinstall mysql. In order to avoid the trouble of importing this data from other places, first make a backup of the database file of the current library (/var/lib/mysql/location). Next, I uninstalled the Perconaserver 5.7 package, reinstalled the original 5.1.71 package, started the mysql service, and it prompted Unknown/unsupportedtabletype:innodb and could not start normally. 11050912:04:27InnoDB:Initializingbufferpool,size=384.0M11050912:04:27InnoDB:Complete

1. Mysql transaction isolation level These four isolation levels, when there are multiple transaction concurrency conflicts, some problems of dirty reading, non-repeatable reading, and phantom reading may occur, and innoDB solves them in the repeatable read isolation level mode. A problem of phantom reading, 2. What is phantom reading? Phantom reading means that in the same transaction, the results obtained when querying the same range twice before and after are inconsistent as shown in the figure. In the first transaction, we execute a range query. At this time, there is only one piece of data that meets the conditions. In the second transaction, it inserts a row of data and submits it. When the first transaction queries again, the result obtained is one more than the result of the first query. Data, note that the first and second queries of the first transaction are both in the same

MySQL storage engine selection comparison: InnoDB, MyISAM and Memory performance index evaluation Introduction: In the MySQL database, the choice of storage engine plays a vital role in system performance and data integrity. MySQL provides a variety of storage engines, the most commonly used engines include InnoDB, MyISAM and Memory. This article will evaluate the performance indicators of these three storage engines and compare them through code examples. 1. InnoDB engine InnoDB is My

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

MySQL is a widely used database management system, and different storage engines have different impacts on database performance. MyISAM and InnoDB are the two most commonly used storage engines in MySQL. They have different characteristics and improper use may affect the performance of the database. This article will introduce how to use these two storage engines to optimize MySQL performance. 1. MyISAM storage engine MyISAM is the most commonly used storage engine for MySQL. Its advantages are fast speed and small storage space. MyISA

Tips and strategies to improve the read performance of MySQL storage engine: Comparative analysis of MyISAM and InnoDB Introduction: MySQL is one of the most commonly used open source relational database management systems, mainly used to store and manage large amounts of structured data. In applications, the read performance of the database is often very important, because read operations are the main type of operations in most applications. This article will focus on how to improve the read performance of the MySQL storage engine, focusing on a comparative analysis of MyISAM and InnoDB, two commonly used storage engines.
