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导入原数据,这个也很好理解.--//这样的操作模 ...
随机推荐
- Deferred跟promise跟js同步问题记录
之前的时候,碰到过几次同事问我,说js的同步怎么处理,就是我想先执行这段代码(耗时相对较长的一行,多数是异步的一些api调用),执行完了之后我再执行下边这句,每次我都很无奈的说不晓得,如果是ajax的 ...
- 安装rails遇到的问题
1 要安装js运行环境,例如Nodejs,如果使用nvm记得,安装完执行nvm use '版本号' 2 或者在Gemfile文件中加入: gem 'execjs'gem 'therubyracer'然 ...
- redis开机启动,有密码
#!/bin/sh # chkconfig: # description: Start and Stop redis REDISPORT= EXEC=/usr/local/redis/src/redi ...
- C#中实体集合和实体转换成相应的string、XDocument、XElement
C#中实体集合和实体转换成相应的string.XDocument.XElement public class SimpleXmlConverter { public static string ToX ...
- Windows Store 应用获得设备 ID 的几种方案
本文为个人博客备份文章,原文地址: http://validvoid.net/solutions-get-device-id-for-uwp/ 通过生成唯一的设备 ID 进行数据统计是应用开发中一个非 ...
- WebService的搭建,部署,简单应用和实体类结合使用
WebService:一种跨编程语言和操作系统平台的远程调用技术,SOAP.WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescription ...
- Xtrareport 报表的一些属性及控件
基本概念: XtraReports 中的每个报表都由 XtraRepot 类的一个实例表示,或者由该类的子类来表示(这种情况更常见). 因此,每个报表都作为带区的容器使用,而每个带区中都包含报表控件. ...
- c# 截取picturebox部分图像
Bitmap bit = new Bitmap(renderImage.Width, renderImage.Height); using (Graphics g = Graphics.FromIma ...
- npm 包下载很慢的解决办法
原因: 国内访问外网都很慢,甚至不能访问!安装Node时自带的npm地址默认是:http://registry.npmjs.org 三种方法: 1.通过config命令 npm config set ...
- transient和volatile
transient和volatile两个关键字一个用于对象序列化,一个用于线程同步,都是Java中比较高阶的话题,简单总结一下. transient transient是类型修饰符,只能用来修饰字段. ...