利用.frm、.ibd恢复数据

我们知道启用innodb_file_per_table选项后,单个表(InnoDB引擎)的数据和索引放入单独的文件中(.ibd),建表语句保存在.frm文件中
本文假设192.168.85.132,3306实例无法启动(磁盘还能访问),需要将原实例下的replcrash.py_user表恢复到192.168.85.132,3308实例

一、.frm得到建表语句

mysqlfrm可以读取.frm文件并从该文件中找到表定义数据生成CREATE语句。在大多数情况下,生成的CREATE语句用于在另一个服务器上创建表或进行诊断等。

1.1、操作模式

默认模式,使用--basedir或者--server选项生成一个临时实例,该模式需要指定--port选项给临时实例使用,该端口不能与现有的实例冲突。在读取.frm文件后,临时实例将被关闭,所有的临时文件将被删除。
诊断模式,使用--diagnostic选项。byte-by-byte读取.frm文件,尽可能多的恢复信息。
诊断模式可能遇到的问题
• 不能解读character set/collation values,这会影响到多字节字符列大小
• 不能读取默认值
• 生成的create语句可能会有语法错误
当使用默认模式无法读取文件,或者服务器上没有安装MySQL实例时就使用诊断模式~~

1.2、mysqlfrm安装使用

1、安装
# mysql-utilities依赖mysql-connector-python >= 2.0.0
[[email protected] tools]# wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.7-1.el6.x86_64.rpm
[[email protected] tools]# wget https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el6.noarch.rpm
# 安装
[[email protected] tools]# yum localinstall mysql-connector-python-2.1.7-1.el6.x86_64.rpm -y
[[email protected] tools]# yum localinstall mysql-utilities-1.6.5-1.el6.noarch.rpm -y

2、使用
# default mode
# --basedir
[[email protected] ~]# mysqlfrm --basedir=/usr/local/mysql/ /data/mysql/mysql3306/data/replcrash/py_user.frm --port=3333 --user=root
# --server
[[email protected] ~]# mysqlfrm --server=mydba:[email protected]192.168.85.132:3306 /data/mysql/mysql3308/data/replcrash/py_user.frm --port=3333 --user=root
官方不推荐使用root用户Running spawned server

# diagnostic mode
[[email protected] ~]# mysqlfrm --diagnostic /data/mysql/mysql3308/data/replcrash/py_user.frm

故障实例OFFLINE状态,建议使用--basedir得到建表语句

1.3、mysqlfrm逻辑(default mode)

在命令行末尾添加 -vvv 可以查看执行详细步骤

[[email protected] ~]# mysqlfrm --basedir=/usr/local/mysql/ /data/mysql/mysql3306/data/replcrash/py_user.frm --port=3333 --user=root -vvv
# Checking read access to .frm files
# Creating a temporary datadir = /tmp/tmpktcZWc
# Spawning server with --user=root.
# Starting the spawned server on port 3333 ...
# Cloning the MySQL server located at /usr/local/mysql.
# Configuring new instance...
# Locating mysql tools...
# Location of files:
#                       mysqld: /usr/local/mysql/bin/mysqld
#                   mysqladmin: /usr/local/mysql/bin/mysqladmin
# Setting up empty database and mysql tables...
2017-12-28T09:36:22.383542Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-28T09:36:24.528222Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-12-28T09:36:24.936974Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-12-28T09:36:25.019189Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 925a5f84-ebb2-11e7-a13e-000c29c1025c.
2017-12-28T09:36:25.024957Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2017-12-28T09:36:25.025657Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.
# Starting new instance of the server...
# Startup command for new server:
/usr/local/mysql/bin/mysqld --no-defaults --basedir=/usr/local/mysql --datadir=/tmp/tmpktcZWc --pid-file=/tmp/tmpktcZWc/clone.pid --port=3333 --server-id=101 --socket=/tmp/tmpktcZWc/mysql.sock --tmpdir=/tmp/tmpktcZWc --user=root
# Testing connection to new instance...
2017-12-28T09:36:29.346999Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-28T09:36:29.369718Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-12-28T09:36:29.369837Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.19) starting as process 9382 ...
2017-12-28T09:36:29.387216Z 0 [Note] InnoDB: PUNCH HOLE support available
2017-12-28T09:36:29.387287Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-12-28T09:36:29.387309Z 0 [Note] InnoDB: Uses event mutexes
2017-12-28T09:36:29.387334Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2017-12-28T09:36:29.387353Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-12-28T09:36:29.387372Z 0 [Note] InnoDB: Using Linux native AIO
2017-12-28T09:36:29.388729Z 0 [Note] InnoDB: Number of pools: 1
2017-12-28T09:36:29.389559Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-12-28T09:36:29.396790Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-12-28T09:36:29.413527Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-12-28T09:36:29.419969Z 0 [Note] InnoDB: page_cleaner coordinator priority: -20
2017-12-28T09:36:29.434005Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-12-28T09:36:29.503503Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-12-28T09:36:29.503705Z 0 [Note] InnoDB: Setting file ‘./ibtmp1‘ size to 12 MB. Physically writing the file full; Please wait ...
2017-12-28T09:36:30.110625Z 0 [Note] InnoDB: File ‘./ibtmp1‘ size is now 12 MB.
2017-12-28T09:36:30.113767Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-12-28T09:36:30.113804Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-12-28T09:36:30.114361Z 0 [Note] InnoDB: Waiting for purge to start
# trying again...
2017-12-28T09:36:30.165192Z 0 [Note] InnoDB: 5.7.19 started; log sequence number 2539315
2017-12-28T09:36:30.165487Z 0 [Note] Plugin ‘FEDERATED‘ is disabled.
2017-12-28T09:36:30.175080Z 0 [Note] InnoDB: Loading buffer pool(s) from /tmp/tmpktcZWc/ib_buffer_pool
2017-12-28T09:36:30.176769Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2017-12-28T09:36:30.176801Z 0 [Note] Server hostname (bind-address): ‘*‘; port: 3333
2017-12-28T09:36:30.176922Z 0 [Note] IPv6 is available.
2017-12-28T09:36:30.176941Z 0 [Note]   - ‘::‘ resolves to ‘::‘;
2017-12-28T09:36:30.176987Z 0 [Note] Server socket created on IP: ‘::‘.
2017-12-28T09:36:30.190355Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171228 17:36:30
2017-12-28T09:36:30.211166Z 0 [Note] Event Scheduler: Loaded 0 events
2017-12-28T09:36:30.211365Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.7.19‘  socket: ‘/tmp/tmpktcZWc/mysql.sock‘  port: 3333  MySQL Community Server (GPL)
2017-12-28T09:36:30.211377Z 0 [Note] Executing ‘SELECT * FROM INFORMATION_SCHEMA.TABLES;‘ to get a list of tables using the deprecated partition engine. You may use the startup option ‘--disable-partition-engine-check‘ to skip this check.
2017-12-28T09:36:30.211381Z 0 [Note] Beginning of list of non-natively partitioned tables
2017-12-28T09:36:30.241025Z 0 [Note] End of list of non-natively partitioned tables
# trying again...
# Success!
# Setting the root password...
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
# Connection Information:
#  -uroot -proot --socket=/tmp/tmpktcZWc/mysql.sock
#...done.
2017-12-28T09:36:31.297094Z 3 [Note] Aborted connection 3 to db: ‘unconnected‘ user: ‘root‘ host: ‘localhost‘ (Got an error reading communication packets)
# Connecting to spawned server
done.
# Reading .frm files
#
# Reading the py_user.frm file.
# Changing engine for .frm file /tmp/tmpktcZWc/replcrash_temp/py_user.frm:
# Skipping to header at : 2
# General Data from .frm file:
{‘IO_SIZE‘: 4096,
 ‘MYSQL_VERSION_ID‘: 50719,
 ‘avg_row_length‘: 0,
 ‘charset_low‘: 0,
 ‘create_options‘: 9,
 ‘db_create_pack‘: 2,
 ‘default_charset‘: 33,
 ‘default_part_eng‘: 0,
 ‘extra_size‘: 33,
 ‘frm_file_ver‘: 5,
 ‘frm_version‘: 10,
 ‘key_block_size‘: 0,
 ‘key_info_length‘: 33,
 ‘key_length‘: 361,
 ‘legacy_db_type‘: ‘INNODB‘,
 ‘length‘: 12288,
 ‘max_rows‘: 0,
 ‘min_rows‘: 0,
 ‘rec_length‘: 138,
 ‘row_type‘: 0,
 ‘table_charset‘: 33,
 ‘tmp_key_length‘: 361}
# Engine string: InnoDB
# Server version in file: 5.7.19
#
# CREATE statement for /data/mysql/mysql3306/data/replcrash/py_user.frm:
#

CREATE TABLE `replcrash`.`py_user` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT NULL,
  `add_time` datetime DEFAULT NULL,
  `server_id` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

# Shutting down spawned server
# Removing the temporary datadir
2017-12-28T09:36:31.471827Z 0 [Note] Giving 0 client threads a chance to die gracefully
2017-12-28T09:36:31.471874Z 0 [Note] Shutting down slave threads
2017-12-28T09:36:31.471891Z 0 [Note] Forcefully disconnecting 0 remaining clients
2017-12-28T09:36:31.471908Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2017-12-28T09:36:31.473626Z 0 [Note] Binlog end
2017-12-28T09:36:31.473789Z 0 [Note] Shutting down plugin ‘ngram‘
2017-12-28T09:36:31.473820Z 0 [Note] Shutting down plugin ‘BLACKHOLE‘
2017-12-28T09:36:31.473839Z 0 [Note] Shutting down plugin ‘ARCHIVE‘
2017-12-28T09:36:31.473853Z 0 [Note] Shutting down plugin ‘partition‘
2017-12-28T09:36:31.473866Z 0 [Note] Shutting down plugin ‘INNODB_SYS_VIRTUAL‘
2017-12-28T09:36:31.473880Z 0 [Note] Shutting down plugin ‘INNODB_SYS_DATAFILES‘
2017-12-28T09:36:31.473893Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESPACES‘
2017-12-28T09:36:31.473905Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN_COLS‘
2017-12-28T09:36:31.473918Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN‘
2017-12-28T09:36:31.473931Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FIELDS‘
2017-12-28T09:36:31.473943Z 0 [Note] Shutting down plugin ‘INNODB_SYS_COLUMNS‘
2017-12-28T09:36:31.473956Z 0 [Note] Shutting down plugin ‘INNODB_SYS_INDEXES‘
2017-12-28T09:36:31.473969Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESTATS‘
2017-12-28T09:36:31.473981Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLES‘
2017-12-28T09:36:31.474010Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_TABLE‘
2017-12-28T09:36:31.474024Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_CACHE‘
2017-12-28T09:36:31.474036Z 0 [Note] Shutting down plugin ‘INNODB_FT_CONFIG‘
2017-12-28T09:36:31.474156Z 0 [Note] Shutting down plugin ‘INNODB_FT_BEING_DELETED‘
2017-12-28T09:36:31.474175Z 0 [Note] Shutting down plugin ‘INNODB_FT_DELETED‘
2017-12-28T09:36:31.474188Z 0 [Note] Shutting down plugin ‘INNODB_FT_DEFAULT_STOPWORD‘
2017-12-28T09:36:31.474214Z 0 [Note] Shutting down plugin ‘INNODB_METRICS‘
2017-12-28T09:36:31.474227Z 0 [Note] Shutting down plugin ‘INNODB_TEMP_TABLE_INFO‘
2017-12-28T09:36:31.474241Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_POOL_STATS‘
2017-12-28T09:36:31.474256Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE_LRU‘
2017-12-28T09:36:31.474269Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE‘
2017-12-28T09:36:31.474281Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX_RESET‘
2017-12-28T09:36:31.474303Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX‘
2017-12-28T09:36:31.474317Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM_RESET‘
2017-12-28T09:36:31.474330Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM‘
2017-12-28T09:36:31.474343Z 0 [Note] Shutting down plugin ‘INNODB_CMP_RESET‘
2017-12-28T09:36:31.474356Z 0 [Note] Shutting down plugin ‘INNODB_CMP‘
2017-12-28T09:36:31.474369Z 0 [Note] Shutting down plugin ‘INNODB_LOCK_WAITS‘
2017-12-28T09:36:31.474382Z 0 [Note] Shutting down plugin ‘INNODB_LOCKS‘
2017-12-28T09:36:31.474395Z 0 [Note] Shutting down plugin ‘INNODB_TRX‘
2017-12-28T09:36:31.474407Z 0 [Note] Shutting down plugin ‘InnoDB‘
2017-12-28T09:36:31.474590Z 0 [Note] InnoDB: FTS optimize thread exiting.
2017-12-28T09:36:31.476410Z 0 [Note] InnoDB: Starting shutdown...
2017-12-28T09:36:31.577509Z 0 [Note] InnoDB: Dumping buffer pool(s) to /tmp/tmpktcZWc/ib_buffer_pool
2017-12-28T09:36:31.577612Z 0 [ERROR] InnoDB: Cannot open ‘/tmp/tmpktcZWc/ib_buffer_pool.incomplete‘ for writing: No such file or directory
2017-12-28T09:36:33.117642Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2539334
2017-12-28T09:36:33.117712Z 0 [Note] Shutting down plugin ‘MEMORY‘
2017-12-28T09:36:33.117727Z 0 [Note] Shutting down plugin ‘PERFORMANCE_SCHEMA‘
2017-12-28T09:36:33.117761Z 0 [Note] Shutting down plugin ‘MRG_MYISAM‘
2017-12-28T09:36:33.117767Z 0 [Note] Shutting down plugin ‘MyISAM‘
2017-12-28T09:36:33.117783Z 0 [Note] Shutting down plugin ‘CSV‘
2017-12-28T09:36:33.117790Z 0 [Note] Shutting down plugin ‘sha256_password‘
2017-12-28T09:36:33.117794Z 0 [Note] Shutting down plugin ‘mysql_native_password‘
2017-12-28T09:36:33.117966Z 0 [Note] Shutting down plugin ‘binlog‘
2017-12-28T09:36:33.118884Z 0 [Note] Unable to delete pid file: No such file or directory
2017-12-28T09:36:33.118898Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[[email protected] ~]# 

• 检查读取.frm文件的权限
• 创建临时datadir
• 克隆生成新实例
• 启动、连接新实例
• 读取.frm文件,生成create语句
• 关闭新实例,删除临时datadir
mysqlfrm的使用参考:5.13 mysqlfrm — File reader for .frm files3.3.2 How do you recover the CREATE statement from a damaged or offline server?

二、恢复表数据

这里用到表空间传输,恢复环境使用mysqlfrm得到语句创建相同结构的数据表,然后discard表空间,拷贝故障实例下的ibd文件并修改权限,重新载入表空间,载入过程会有警告,但不影响数据的读取

# 将mysqlfrm得到建表语句拷贝到192.168.85.132,3308上执行
[email protected]192.168.85.132,3308 [(none)]> use replcrash;
[email protected]192.168.85.132,3308 [replcrash]> drop table if exists py_user;
# 执行mysqlfrm得到的create语句
[email protected]192.168.85.132,3308 [replcrash]> CREATE TABLE `replcrash`.`py_user` (
    ->   `uid` int(11) NOT NULL AUTO_INCREMENT,
    ->   `name` varchar(32) DEFAULT NULL,
    ->   `add_time` datetime DEFAULT CURRENT_TIMESTAMP,
    ->   `server_id` varchar(10) DEFAULT NULL,
    ->   PRIMARY KEY (`uid`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.17 sec)

# discard 表空间
[email protected]192.168.85.132,3308 [replcrash]> alter table py_user discard tablespace;
Query OK, 0 rows affected (0.86 sec)

# 拷贝ibd文件,并修改权限
[[email protected] ~]# scp /data/mysql/mysql3306/data/replcrash/py_user.ibd 192.168.85.132:/data/mysql/mysql3308/data/replcrash/
[[email protected] ~]# chown -R mysql:mysql /data/mysql/mysql3308/data/replcrash/py_user.ibd

# 载入表空间
[email protected]192.168.85.132,3308 [replcrash]> alter table py_user import tablespace;
Query OK, 0 rows affected, 1 warning (0.24 sec)

[email protected]192.168.85.132,3308 [replcrash]> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                           |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory) Error opening ‘./replcrash/py_user.cfg‘, will attempt to import without schema verification |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

# 查询数据是否一致
[email protected]192.168.85.132,3308 [replcrash]> select * from py_user;
+-----+------------------------------+---------------------+-----------+
| uid | name                         | add_time            | server_id |
+-----+------------------------------+---------------------+-----------+
|   1 | U4F9ZKZTJ9GK6RFV4A3EEJ       | 2017-12-21 10:46:44 | 1323306   |
|   2 | IB1FSWGFEH5CGIT4FWEZK81V     | 2017-12-21 10:47:14 | 1323306   |
|   3 | 9N9TF1C8SEGKXNHBUE6CPOXD0IUU | 2017-12-21 10:47:15 | 1323306   |
|   4 | TEBD44BM3E0NZPSIVGI79Z       | 2017-12-21 10:47:16 | 1323306   |
|   5 | XS8Z2W2XIDIB5Y4TMF78L9INM7   | 2017-12-21 10:47:17 | 1323306   |
|   6 | OP65BAJ6MNI1W02PNMJGHXX      | 2017-12-21 10:47:18 | 1323306   |
|   7 | 19R173XU7QXRPG21413BYMWMY1   | 2017-12-21 10:47:19 | 1323306   |
|   8 | 768NGEAGK0VJ57MW98SG         | 2017-12-21 10:58:02 | 1323306   |
|   9 | 9EDYG3U7LFL80WIDKSV5JTI      | 2017-12-21 11:03:41 | 1323306   |
+-----+------------------------------+---------------------+-----------+
9 rows in set (0.00 sec)

三、表空间传输

前面重新载入表空间时出现了警告,是因为我们假设3306实例出现故障,数据库无法启动,因此不能按照正常的表空间传输步骤操作

# InnoDB表空间传输迁移数据
1、迁出实例3306
[email protected]192.168.85.132,3306 [(none)]> use replcrash;
[email protected]192.168.85.132,3306 [replcrash]> select count(*) from py_user;
[email protected]192.168.85.132,3306 [replcrash]> show create table py_user;

2、迁入实例3308
# 创建表
[email protected]192.168.85.132,3308 [(none)]> use replcrash;
[email protected]192.168.85.132,3308 [replcrash]> CREATE TABLE `py_user` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT NULL,
  `add_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `server_id` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB;

# 查看相关文件
[[email protected] ~]# ll /data/mysql/mysql3308/data/replcrash/py_user*
-rw-r-----. 1 mysql mysql  8666 Dec 20 16:57 /data/mysql/mysql3308/data/replcrash/py_user.frm
-rw-r-----. 1 mysql mysql 98304 Dec 20 16:57 /data/mysql/mysql3308/data/replcrash/py_user.ibd
[[email protected] ~]# 

# discard 表空间,.ibd文件会被删除
[email protected]192.168.85.132,3308 [replcrash]> alter table py_user discard tablespace;

# 再次查看相关文件
[[email protected] ~]# ll /data/mysql/mysql3308/data/replcrash/py_user*
-rw-r-----. 1 mysql mysql 8666 Dec 20 16:57 /data/mysql/mysql3308/data/replcrash/py_user.frm
[[email protected] ~]# 

3、迁出实例3306
[email protected]192.168.85.132,3306 [replcrash]> flush tables py_user for export;
这个时候会加表锁,只能读不能写,同时会产生一个py_user.cfg文件
[[email protected] ~]# ll /data/mysql/mysql3306/data/replcrash/py_user*
-rw-r-----. 1 mysql mysql    517 Dec 20 17:03 /data/mysql/mysql3306/data/replcrash/py_user.cfg
-rw-r-----. 1 mysql mysql   8666 Nov 30 09:23 /data/mysql/mysql3306/data/replcrash/py_user.frm
-rw-r-----. 1 mysql mysql 376832 Dec 20 17:03 /data/mysql/mysql3306/data/replcrash/py_user.ibd
[[email protected] ~]#

# 将.idb、.cfg拷贝到迁入实例对应目录
[[email protected] ~]# scp /data/mysql/mysql3306/data/replcrash/py_user.{cfg,ibd} 192.168.85.132:/data/mysql/mysql3308/data/replcrash/

# 解除锁定
[email protected]192.168.85.132,3306 [replcrash]> unlock tables;

4、迁入实例3308
# 修改文件权限
[[email protected] ~]# chown mysql.mysql /data/mysql/mysql3308/data/replcrash/py_user.{ibd,cfg}
# 导入表空间文件
[email protected]192.168.85.132,3308 [replcrash]> alter table py_user import tablespace; 

到这里整个innodb表就被迁移完成,比起逻辑(mysqldump)或物理备份(xtrabackup)方便很多

知晓基于.frm、.ibd恢复数据,再去阅读从完整备份恢复单个innodb表就简单了

原文地址:https://www.cnblogs.com/Uest/p/8075145.html

时间: 2024-07-29 02:55:28

利用.frm、.ibd恢复数据的相关文章

Mysql ibdata 丢失或损坏如何通过frm&ibd 恢复数据

mysql存储在磁盘中,各种天灾人祸都会导致数据丢失.大公司的时候我们常常需要做好数据冷热备,对于小公司来说要做好所有数据备份需要支出大量的成本,很多公司也是不现实的.万一还没有做好备份,数据被误删除了,或者ibdata损坏了怎么办呢?别担心,只要有部分的frm.ibd存在就可以恢复部分数据. 注意:一.这个是对innodb的数据恢复.myisam不需要这么麻烦,只要数据文件存在直接复制过去就可以.二.大家的mysql数据库必须是按表存放数据的,默认不是,但是大家生产肯定是按分表设置的吧,如果不

Mysql 通过frm&ibd 恢复数据

mysql存储在磁盘中,各种天灾人祸都会导致数据丢失.大公司的时候我们常常需要做好数据冷热备,对于小公司来说要做好所有数据备份需要支出大量的成本,很多公司也是不现实的.万一还没有做好备份,数据被误删除了,或者ibdata损坏了怎么办呢?别担心,只要有部分的frm.ibd存在就可以恢复部分数据. 注意: 一.这个是对innodb的数据恢复.myisam不需要这么麻烦,只要数据文件存在直接复制过去就可以. 二.大家的mysql数据库必须是按表存放数据的,默认不是,但是大家生产肯定是按分表设置的吧,如

MySQL 5.6.26 通过frm & ibd 恢复数据过程

在A服务器上创建数据库yoonroot(yoon)> show create table yoon\G*************************** 1. row *************************** Table: yoonCreate Table: CREATE TABLE `yoon` ( `id` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET

Mysql之binlog日志说明及利用binlog日志恢复数据操作记录

众所周知,binlog日志对于mysql数据库来说是十分重要的.在数据丢失的紧急情况下,我们往往会想到用binlog日志功能进行数据恢复(定时全备份+binlog日志恢复增量数据部分),化险为夷! 废话不多说,下面是梳理的binlog日志操作解说: 一.初步了解binlogMySQL的二进制日志binlog可以说是MySQL最重要的日志,它记录了所有的DDL和DML语句(除了数据查询语句select),以事件形式记录,还包含语句所执行的消耗的时间,MySQL的二进制日志是事务安全型的. DDL-

利用sqlserver日志恢复数据

如果你已经急的焦头烂额,看到这篇文章的时候,请你换个坐姿,深呼吸几次,静下心来将这篇文章读完,也许你的问题迎刃而解. 我遇 到的情况是这样的,网站被植入木马,盗取了我的web.config文件,web.config文件里面的数据库连接字符串没有加密,而我的数据库远程连 接又没有做IP限制,黑客通过数据库客户端连上我的数据库后,将所有的表都Delete掉了,所以大家一定要有一个好习惯将数据库连接字符串加密或者对远程访问数据库的IP作限制. 因被黑客Delete掉所有数据的具体时间点我不清楚,所以我

MsSQL利用日志备份恢复到某一时间点

在做update或delete操作时忘带where条件或where条件精度不够,执行之后导致数据丢失或更新错误等严重后果,如果你的数据库已有相应的完整备份,并且不能备份日志(truncate log on checkpoint选项为1)可以利用事务日志的备份来进行数据恢复. 恢复数据具体步骤如下: 1,首先要做的事就是进行一次日志备份(如果为了不让日志文件变大而置trunc. log on chkpt.选项为1那就没法子了)     backup log dbName to disk='D:\N

MySQL借助ibd文件恢复数据技巧?

磁盘坏道.断电等意外不是常态,但遇上了就足够你"惊心动魄"!如果是数据库损坏造成的数据丢失,Binlog也不可用了,怎么办?为了在短时间内无损恢复数据以保证业务稳定性,除了利用binlog,我们还修炼了一招新的恢复技能! 还记得我们之前写过的<只需一招,让失控的研发爱上你>吗?前文提到过我们日常使用的比较多的两种数据库恢复方法是: 以上两种方法都可以实现实时性的回档,但是你会认为有了这两种技能就够了吗? 不-.! 在线上这种错综复杂的架构中,其实还有很多未知的原因,我们是没

MySQL表结构为InnoDB类型从ibd文件恢复数据

客户的机器系统异常关机,重启后mysql数据库不能正常启动,重装系统后发现数据库文件损坏,悲催的是客户数据库没有进行及时备份,只能想办法从数据库文件当中恢复,查找资料,试验各种方法,确认下面步骤可行: 一.找回表结构,如果表结构没有丢失直接到下一步 a.先创建一个数据库,这个数据库必须是没有表和任何操作的. b.创建一个表结构,和要恢复的表名是一样的.表里的字段无所谓.一定要是innodb引擎的.CREATE TABLE `test`(  `testID` bigint(20)) ENGINE=

亲测Mysql表结构为InnoDB类型从ibd文件恢复数据

客户的机器系统异常关机,重启后mysql数据库不能正常启动,重装系统后发现数据库文件损坏,悲催的是客户数据库没有进行及时备份,只能想办法从数据库文件当中恢复,查找资料,试验各种方法,确认下面步骤可行: 一.找回表结构,如果表结构没有丢失直接到下一步 a.先创建一个数据库,这个数据库必须是没有表和任何操作的. b.创建一个表结构,和要恢复的表名是一样的.表里的字段无所谓.一定要是innodb引擎的.CREATE TABLE `test`(  `testID` bigint(20)) ENGINE=