MySQL另类的备份恢复方法——innodb可传输表空间
- Transport a single table to report server without influencing loads on product.
- Transport a single table to slave server for correcting the replication errors about the table.
- Transport a single table to better storages such as ssd device for special purpose.
- Restore a big table efficiently and swiftly as mysqldump needs to reinsert data and rebuild indexes.
- "innodb_file_per_table" should be set to "on"(the same to slave server if in replication structure).
- Page size on instance of target server should be same as the one on source server.
- It doesn't support partition table and tables which contains fulltext indexes.
- "foreign_key_checks" should be set to "0" if there's a paraent-child relationship in a table.
- It doesn't check the foreign key constraints when importing,so all relevant tables should be exported at the same time.
- Target instance must has the same version of series with the source instance.
- it's recommended to set "lower_case_table" to "1" to avoid import problems.
(root@localhost mysql3306.sock)[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+--------------------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>show create table sbtest2\G
*************************** . row ***************************
Table: sbtest2
Create Table: CREATE TABLE `sbtest2` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL DEFAULT '',
`c` char() NOT NULL DEFAULT '',
`pad` char() NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_2` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8
row in set (0.00 sec) (root@localhost mysql3306.sock)[sysbench]>select count(*) from sbtest2;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.07 sec) (root@localhost mysql3306.sock)[sysbench]>show variables like '%innodb_file_per_table%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
row in set (0.00 sec)
(root@localhost mysql3306.sock)[tt]>CREATE TABLE `sbtest2` (
-> `id` int() NOT NULL AUTO_INCREMENT,
-> `k` int() NOT NULL DEFAULT '',
-> `c` char() NOT NULL DEFAULT '',
-> `pad` char() NOT NULL DEFAULT '',
-> PRIMARY KEY (`id`),
-> KEY `k_2` (`k`)
-> ) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8;
Query OK, rows affected (0.02 sec) (root@localhost mysql3306.sock)[tt]>select count(*) from sbtest2;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[tt]>show variables like '%innodb_file_per_table%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
row in set (0.00 sec)
(root@localhost mysql3306.sock)[zlm]>alter table sbtest2 discard tablespace;
Query OK, rows affected (0.00 sec) [root@zlm3 :: /data/mysql/mysql3306/data/tt]
#ls -l
total
-rw-r----- mysql mysql Jul : db.opt
-rw-r----- mysql mysql Jul : sbtest2.frm //The sbtest2.ibd file has been deleted.
(root@localhost mysql3306.sock)[sysbench]>flush table sbtest2 for export;
Query OK, rows affected (0.00 sec) [root@zlm2 :: /data/mysql/mysql3306/data/sysbench]
#ls -l|grep sbtest2
-rw-r----- mysql mysql Jul : sbtest2.cfg
-rw-r----- mysql mysql Jul : sbtest2.frm
-rw-r----- mysql mysql Jul : sbtest2.ibd //A .cfg file has been created now. --05T08::.515902Z [Note] InnoDB: Sync to disk of `sysbench`.`sbtest2` started.
--05T08::.515929Z [Note] InnoDB: Stopping purge
--05T08::.516147Z [Note] InnoDB: Writing table metadata to './sysbench/sbtest2.cfg'
--05T08::.516276Z [Note] InnoDB: Table `sysbench`.`sbtest2` flushed to disk //error log shows the information after flush operation.
//table metadata has been written into the .cfg file.
[root@zlm2 :: /data/mysql/mysql3306/data/sysbench]
#scp sbtest2.{ibd,cfg} zlm3:/data/mysql/mysql3306/data/tt/
root@zlm3's password:
sbtest2.ibd % 29MB .0MB/s :
sbtest2.cfg % .6KB/s :
(root@localhost mysql3306.sock)[sysbench]>unlock tables;
Query OK, rows affected (0.00 sec) [root@zlm2 :: /data/mysql/mysql3306/data/sysbench]
#ls -l|grep sbtest2
-rw-r----- mysql mysql Jul : sbtest2.frm
-rw-r----- mysql mysql Jul : sbtest2.ibd --05T08::.256442Z [Note] InnoDB: Deleting the meta-data file './sysbench/sbtest2.cfg'
--05T08::.256458Z [Note] InnoDB: Resuming purge //The .cfg file will be deleted after execute "unlock tables;"
[root@zlm3 :: /data/mysql/mysql3306/data/tt]
#ls -l
total
-rw-r----- mysql mysql Jul : db.opt
-rw-r----- root root Jul : sbtest2.cfg
-rw-r----- mysql mysql Jul : sbtest2.frm
-rw-r----- root root Jul : sbtest2.ibd //change the root.root to mysql.mysql [root@zlm3 :: /data/mysql/mysql3306/data/tt]
#chown mysql.mysql sbtest2.* [root@zlm3 :: /data/mysql/mysql3306/data/tt]
#ls -l
total
-rw-r----- mysql mysql Jul : db.opt
-rw-r----- mysql mysql Jul : sbtest2.cfg
-rw-r----- mysql mysql Jul : sbtest2.frm
-rw-r----- mysql mysql Jul : sbtest2.ibd
(root@localhost mysql3306.sock)[tt]>alter table sbtest2 import tablespace;
Query OK, rows affected, warning (2.68 sec) (root@localhost mysql3306.sock)[tt]>show tables;
+--------------+
| Tables_in_tt |
+--------------+
| sbtest2 |
+--------------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[tt]>select count(*) from sbtest2;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.06 sec) --05T08::.820441Z [Note] InnoDB: Importing tablespace for table 'sysbench/sbtest2' that was exported from host 'zlm2'
--05T08::.820441Z [Note] InnoDB: Phase I - Update all pages
--05T08::.859485Z [Note] InnoDB: Sync to disk
--05T08::.936351Z [Note] InnoDB: Sync to disk - done!
--05T08::.962775Z [Note] InnoDB: Phase III - Flush changes to disk
--05T08::.975519Z [Note] InnoDB: Phase IV - Flush complete
--05T08::.975722Z [Note] InnoDB: `tt`.`sbtest2` autoinc value set to //The error log shows details of this import operation.
(root@localhost mysql3306.sock)[tt]>alter table sbtest2 discard tablespace;
Query OK, rows affected (0.01 sec) (root@localhost mysql3306.sock)[tt]>alter table sbtest2 discard tablespace;
Query OK, rows affected, warning (0.00 sec) (root@localhost mysql3306.sock)[tt]>show warnings;
+---------+------+-----------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------+
| Warning | | InnoDB: Tablespace is missing for table tt/sbtest2. |
+---------+------+-----------------------------------------------------+
row in set (0.00 sec) --05T08::.055225Z [ERROR] InnoDB: Cannot delete tablespace because it is not found in the tablespace memory cache.
--05T08::.055226Z [Warning] InnoDB: Cannot delete tablespace in DISCARD TABLESPACE: Tablespace not found //error log shows the ERROR & Warning because of the .ibd file has been deleted in first discard operation.
[root@zlm2 :: /data/mysql/mysql3306/data/sysbench]
#scp sbtest2.{ibd,cfg} zlm3:/data/mysql/mysql3306/data/tt/
root@zlm3's password:
sbtest2.ibd % 29MB .0MB/s :
sbtest2.cfg: No such file or directory //Because of "unlock tables" operation,the .cfg file has gone now.
(root@localhost mysql3306.sock)[tt]>alter table sbtest2 import tablespace;
Query OK, rows affected, warning (2.34 sec) (root@localhost mysql3306.sock)[tt]>show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | | InnoDB: IO Read error: (, No such file or directory) Error opening './tt/sbtest2.cfg', will attempt to import without schema verification |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+
row in set (0.00 sec) //There's a warning about importing without .cfg file which won't impact the result.
- Transportable Tablespace(TT) of innodb provids a different way in backing up and restoring a single table between servers.
- TT merely supports innodb engine which can store data in tablespaces of their own by setting "innodb_file_per_table=1".
- TT supports importing tablespace without .cfg file what brings about us much convenience in crash recovery.
- Notice that there will be shared read locks on the tables after execute "flush table ... for export;" what really influences the tables need to be write.
MySQL另类的备份恢复方法——innodb可传输表空间的更多相关文章
- 从完整备份恢复单个innodb表
现在大多数同学在线上采取的备份策略都是xtrabackup全备+binlog备份,那么当某天某张表意外的删除那么如何从xtrabackup全备中恢复呢?从mysql 5.6版本开始,支持可移动表空间( ...
- mysql InnoDB引擎 共享表空间和独立表空间(转载)
PS:innodb这种引擎,与MYISAM引擎的区别很大.特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间. 1.什么是共享表空间和独占表空 ...
- 从MySQL全备文件中恢复单个库或者单个表
从MySQL全备文件中恢复单个库或者单个表 提取建库语句 sed -n '/^-- Current Database: db_cms/,/^-- Current Database: `/p' back ...
- InnoDB 引擎独立表空间 innodb_file_per_table
使用过MySQL的同学,刚开始接触最多的莫过于MyISAM表引擎了,这种引擎的数据库会分别创建三个文件:表结构.表索引.表数据空间.我们可以将某个数据库目录直接迁移到其他数据库也可以正常工作.然而当你 ...
- InnoDB 引擎独立表空间
InnoDB 引擎独立表空间 使用过MySQL的同学,刚开始接触最多的莫过于MyISAM表引擎了,这种引擎的数据库会分别创建三个文件:表结构.表索引.表数据空间.我们可以将某个数据库目录直接迁移到 ...
- mysql5.6之 传输表空间迁移表或恢复误删除的表
一,简单说明: 1),传输表空间的限制: 1,mysql 版本 5.6.6 及其以上,并且版本建议源和目标版本建议都是GA版并且大版本一样 2,表引擎为innodb并且开启独立表空间 innod ...
- MySQL 5.7新特性之在线收缩undo表空间
1. MySQL 5.5时代的undo log 在MySQL5.5以及之前,大家会发现随着数据库上线时间越来越长,ibdata1文件(即InnoDB的共享表空间,或者系统表空间)会越来越大,这会造成2 ...
- 用备份控制文件做不完全恢复下的完全恢复(全备<老>--备份控制文件<次新>--删除表空间andy--日志文件<新>)
为什么会使用备份的控制文件? 实际工作中主要有两种情况:第一种:当前控制文件全部损坏,而数据文件备份,控制文件备份及当前日志处于不同SCN版本,它们之间又增加过表空间(数据文件).第二种:当前控制文件 ...
- [20170623]利用传输表空间恢复部分数据.txt
[20170623]利用传输表空间恢复部分数据.txt --//昨天我测试使用传输表空间+dblink,上午补充测试发现表空间设置只读才能执行impdp导入原数据,这个也很好理解.--//这样的操作模 ...
随机推荐
- HDU 4336——Card Collector——————【概率dp】
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 【Iperf】iperf测试wlan的性能
1.概念: iperf命令是一个网络性能测试工具.iperf可以测试TCP和UDP带宽质量. iperf可以测量最大TCP带宽,具有多种参数和UDP特性.iperf可以报告带宽,延迟抖动和数据包丢失. ...
- 网页设计,Access入门 2010,数学
网页设计(表格) 创建表格:插入---表格---设置表格大小---确定.(按Ctrl键可多选单元格) 插入图片在表格:光标在单元格---插入---图像---选择图像---确定. 表格属性:属性(屏幕下 ...
- 使用dtd--属性声明
<!ATTLIST 元素名 属性名称 属性类型 属性特点> 1.属性类型 类型 含义 CDATA 纯文本 enumerated 枚举类型 ID 以属性的方式唯一标识改元素,必须以字母开头 ...
- 在 Excel 中设置图片
package com.smbea.demo.excel; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStr ...
- iOS 谓词(NSPredicate)的应用
Cocoa中谓词(Predicate)提供了一个通用的查询方式处理数据,可以获取和指定数据的过滤形式,Cocoa实际开发中可以是使用NSPredicate及其父类NSComparisonPredica ...
- [原创]在Windows Server 2019上配置NAS
序言 此教程安装的都是最新版本的.由于是当NAS让它非常稳定的运行,所以能不安装的软件尽量不要安装. 一.准备工作 [更新系统] 没啥,就他喵想用个最新的. 右键点击开始键->设置->更新 ...
- mybatis学习目录
mybatis详解动态SQL https://www.cnblogs.com/ysocean/p/7289529.html mybatis查询时间段sql语句 http://www.cnblogs.c ...
- springboot 修改和设置 banner
springboot 修改和设置 banner 先上图 修改步骤 1.在src/main/resources下新建一个banner.txt文档 2.通过http://patorjk.com/softw ...
- Python基本数据类型(一)
一.int的函数说明(部分函数Python2特有,Python3已删除,部分函数Python3新增:) class int(object): """ int(x=0) - ...