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导入原数据,这个也很好理解.--//这样的操作模 ...
随机推荐
- C语言实现通用链表初步(二)
接着上次的内容,我们继续! 还是无头单向非循环链表.假如要删除某个节点,如何实现? //删除成功返回0,失败返回-1 int slist_del(struct node_info *node, str ...
- pat1045. Favorite Color Stripe (30)
1045. Favorite Color Stripe (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- struts2的java.lang.NoSuchMethodException异常处理
1. 你有没有试试看 其它的方法能不能用,要是都是这种情况的话,可能是你的Action类没有继承structs里面的DispatchAction或者其它的类.还有你注意下方法的参数列表,类型顺序要正确 ...
- ANDROID_HOME is not set and "android" command not in your PATH解决
使用nodejs安装cordova后在项目里面添加平台时出现错误: 原因就是没有配环境变量 使用phonegap开发不仅要配JDK环境变量,还要配ADT环境变量,出现这个错误很显示就是没配ADT环境变 ...
- 动态行转列 pivot实现
declare @sql varchar(8000) begin set @sql='' --初始化变量@sql select @sql= ...
- Asp.Net中ObjectDataSource控件传参绑定数据
最近在实习,在上头交付的任务中,由于需要使用Asp.Net的ListView控件,因此必然得就使用了ObjectDataSource控件,由于在使用过程中,需要网页中的参数发送到后台后,运行该参数进行 ...
- 浅谈 ECMAScript 和 JavaScript
ES5与ES3基本保持兼容,较大的语法修正和新功能加入,将由JavaScript.next完成. 什么是ECMAScript?http://baike.baidu.com/link?url=G1T8n ...
- Azure 4月新公布
Azure 4 月新发布:Linux 上的 Azure Service Fabric 公共预览版正式发布:Azure 物联网套件新增设备管理功能:计量名称变更 Linux 上的 Azure Servi ...
- php的yii框架开发总结9
这一篇讲解怎么实现的自动发邮件的功能,我在网上查了很多资料,很多都是用定时检测来实现的,我试过,效率太低,网站也卡了. 后来就写了一个.bat文件来实现刷新页面,用了windows的定时任务定时来运行 ...
- 原生Js在各大浏览器上、火狐、ie、谷歌、360等出现的不兼容问题。
1 document.getElementsByName("name") 在Ie低版本,360普通版本,以及火狐低版本不支持. 2 element.innerText 在低版本的 ...