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导入原数据,这个也很好理解.--//这样的操作模 ...
随机推荐
- pat1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- Java取得一个对象里所有get方法和set方法, 读取某个类下所有变量的名称
所有get方法和set方法public void getMethod(Object obj){ Class clazz=obj.getClass();//获得实体类名 Field[] fields = ...
- SQL——行转列,列转行
行转列,列转行是我们在开发过程中经常碰到的问题.行转列一般通过CASE WHEN 语句来实现,也可以通过 SQL SERVER 2005 新增的运算符PIVOT来实现.用传统的方法,比较好理解.层次清 ...
- CentOS搭建KMS服务器
安装 使用命令: #CentOS,Redhat,Fedora等请选择CentOS脚本 wget https://raw.githubusercontent.com/dakkidaze/one-key- ...
- DJ轮回舞曲网下载教程
该网站网址为:http://www.92cc.com/ 昨天有网友问我这个网站能不能下载.我告诉他,只要能在线试听的就能下载 于是今天出个临时教程 教大家如何获取试听的音乐URL. 第一步找到试听的网 ...
- ios 开发常用函数
rand() ----随机数 abs() / labs() ----整数绝对值 fabs() / fabsf() / fabsl() ----浮点数绝对值 floor() / floorf() / f ...
- js之静态方法与实例方法
静态方法是指不需要声明类的实例就可以使用的方法. 实例方法是指必须要先使用"new"关键字声明一个类的实例, 然后才可以通过此实例访问的方法. function staticCla ...
- Android实现异步的几种方法
在Android项目中,有经验的开发人员都知道,一些耗时的IO操作等都必须在子线程中去操作,那么可以有哪些方法来开启子线程呢,一般可以使用Java中自带的几种方法,也可以使用Andorid特有的一些类 ...
- [原创] Debian9上配置Samba
Samba概述 Samba是一套使用SMB(Server Message Block)协议的应用程序,通过支持这个协议,Samba允许Linux服务器与Windows系统之间进行通信,使跨平台的互访成 ...
- python模块详解 shelve
shelve模块是一个简单的k,v 将内存数据通过文件持久化的模块,可以持久化任何pickle可以支持的python数据.简单的说对 pickle的更上一层的封装. 写文件 import shelve ...