MySQL另类的备份恢复方法——innodb可传输表空间
2018-07-06 01:17:45来源:博客园 阅读 ()
- 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.
1 (root@localhost mysql3306.sock)[sysbench]>show tables; 2 +--------------------+ 3 | Tables_in_sysbench | 4 +--------------------+ 5 | sbtest1 | 6 | sbtest10 | 7 | sbtest2 | 8 | sbtest3 | 9 | sbtest4 | 10 | sbtest5 | 11 | sbtest6 | 12 | sbtest7 | 13 | sbtest8 | 14 | sbtest9 | 15 +--------------------+ 16 10 rows in set (0.00 sec) 17 18 (root@localhost mysql3306.sock)[sysbench]>show create table sbtest2\G 19 *************************** 1. row *************************** 20 Table: sbtest2 21 Create Table: CREATE TABLE `sbtest2` ( 22 `id` int(11) NOT NULL AUTO_INCREMENT, 23 `k` int(11) NOT NULL DEFAULT '0', 24 `c` char(120) NOT NULL DEFAULT '', 25 `pad` char(60) NOT NULL DEFAULT '', 26 PRIMARY KEY (`id`), 27 KEY `k_2` (`k`) 28 ) ENGINE=InnoDB AUTO_INCREMENT=100001 DEFAULT CHARSET=utf8 29 1 row in set (0.00 sec) 30 31 (root@localhost mysql3306.sock)[sysbench]>select count(*) from sbtest2; 32 +----------+ 33 | count(*) | 34 +----------+ 35 | 100000 | 36 +----------+ 37 1 row in set (0.07 sec) 38 39 (root@localhost mysql3306.sock)[sysbench]>show variables like '%innodb_file_per_table%'; 40 +-----------------------+-------+ 41 | Variable_name | Value | 42 +-----------------------+-------+ 43 | innodb_file_per_table | ON | 44 +-----------------------+-------+ 45 1 row in set (0.00 sec)
1 (root@localhost mysql3306.sock)[tt]>CREATE TABLE `sbtest2` ( 2 -> `id` int(11) NOT NULL AUTO_INCREMENT, 3 -> `k` int(11) NOT NULL DEFAULT '0', 4 -> `c` char(120) NOT NULL DEFAULT '', 5 -> `pad` char(60) NOT NULL DEFAULT '', 6 -> PRIMARY KEY (`id`), 7 -> KEY `k_2` (`k`) 8 -> ) ENGINE=InnoDB AUTO_INCREMENT=100001 DEFAULT CHARSET=utf8; 9 Query OK, 0 rows affected (0.02 sec) 10 11 (root@localhost mysql3306.sock)[tt]>select count(*) from sbtest2; 12 +----------+ 13 | count(*) | 14 +----------+ 15 | 0 | 16 +----------+ 17 1 row in set (0.00 sec) 18 19 (root@localhost mysql3306.sock)[tt]>show variables like '%innodb_file_per_table%'; 20 +-----------------------+-------+ 21 | Variable_name | Value | 22 +-----------------------+-------+ 23 | innodb_file_per_table | ON | 24 +-----------------------+-------+ 25 1 row in set (0.00 sec)
1 (root@localhost mysql3306.sock)[zlm]>alter table sbtest2 discard tablespace; 2 Query OK, 0 rows affected (0.00 sec) 3 4 [root@zlm3 10:30:44 /data/mysql/mysql3306/data/tt] 5 #ls -l 6 total 16 7 -rw-r----- 1 mysql mysql 61 Jul 5 10:13 db.opt 8 -rw-r----- 1 mysql mysql 8632 Jul 5 10:31 sbtest2.frm //The sbtest2.ibd file has been deleted.
1 (root@localhost mysql3306.sock)[sysbench]>flush table sbtest2 for export; 2 Query OK, 0 rows affected (0.00 sec) 3 4 [root@zlm2 10:36:01 /data/mysql/mysql3306/data/sysbench] 5 #ls -l|grep sbtest2 6 -rw-r----- 1 mysql mysql 559 Jul 5 10:35 sbtest2.cfg 7 -rw-r----- 1 mysql mysql 8632 Jul 4 09:26 sbtest2.frm 8 -rw-r----- 1 mysql mysql 30408704 Jul 4 09:26 sbtest2.ibd //A .cfg file has been created now. 9 10 2018-07-05T08:35:03.515902Z 9 [Note] InnoDB: Sync to disk of `sysbench`.`sbtest2` started. 11 2018-07-05T08:35:03.515929Z 9 [Note] InnoDB: Stopping purge 12 2018-07-05T08:35:03.516147Z 9 [Note] InnoDB: Writing table metadata to './sysbench/sbtest2.cfg' 13 2018-07-05T08:35:03.516276Z 9 [Note] InnoDB: Table `sysbench`.`sbtest2` flushed to disk 14 15 //error log shows the information after flush operation. 16 //table metadata has been written into the .cfg file.
1 [root@zlm2 10:36:03 /data/mysql/mysql3306/data/sysbench] 2 #scp sbtest2.{ibd,cfg} zlm3:/data/mysql/mysql3306/data/tt/ 3 root@zlm3's password: 4 sbtest2.ibd 100% 29MB 29.0MB/s 00:00 5 sbtest2.cfg 100% 559 0.6KB/s 00:00
1 (root@localhost mysql3306.sock)[sysbench]>unlock tables; 2 Query OK, 0 rows affected (0.00 sec) 3 4 [root@zlm2 10:37:57 /data/mysql/mysql3306/data/sysbench] 5 #ls -l|grep sbtest2 6 -rw-r----- 1 mysql mysql 8632 Jul 4 09:26 sbtest2.frm 7 -rw-r----- 1 mysql mysql 30408704 Jul 4 09:26 sbtest2.ibd 8 9 2018-07-05T08:38:09.256442Z 9 [Note] InnoDB: Deleting the meta-data file './sysbench/sbtest2.cfg' 10 2018-07-05T08:38:09.256458Z 9 [Note] InnoDB: Resuming purge 11 12 //The .cfg file will be deleted after execute "unlock tables;"
1 [root@zlm3 10:39:13 /data/mysql/mysql3306/data/tt] 2 #ls -l 3 total 29716 4 -rw-r----- 1 mysql mysql 61 Jul 5 10:13 db.opt 5 -rw-r----- 1 root root 559 Jul 5 10:36 sbtest2.cfg 6 -rw-r----- 1 mysql mysql 8632 Jul 5 10:31 sbtest2.frm 7 -rw-r----- 1 root root 30408704 Jul 5 10:36 sbtest2.ibd 8 9 //change the root.root to mysql.mysql 10 11 [root@zlm3 10:39:30 /data/mysql/mysql3306/data/tt] 12 #chown mysql.mysql sbtest2.* 13 14 [root@zlm3 10:39:41 /data/mysql/mysql3306/data/tt] 15 #ls -l 16 total 29716 17 -rw-r----- 1 mysql mysql 61 Jul 5 10:13 db.opt 18 -rw-r----- 1 mysql mysql 559 Jul 5 10:36 sbtest2.cfg 19 -rw-r----- 1 mysql mysql 8632 Jul 5 10:31 sbtest2.frm 20 -rw-r----- 1 mysql mysql 30408704 Jul 5 10:36 sbtest2.ibd
1 (root@localhost mysql3306.sock)[tt]>alter table sbtest2 import tablespace; 2 Query OK, 0 rows affected, 1 warning (2.68 sec) 3 4 (root@localhost mysql3306.sock)[tt]>show tables; 5 +--------------+ 6 | Tables_in_tt | 7 +--------------+ 8 | sbtest2 | 9 +--------------+ 10 1 row in set (0.00 sec) 11 12 (root@localhost mysql3306.sock)[tt]>select count(*) from sbtest2; 13 +----------+ 14 | count(*) | 15 +----------+ 16 | 100000 | 17 +----------+ 18 1 row in set (0.06 sec) 19 20 2018-07-05T08:40:03.820441Z 10 [Note] InnoDB: Importing tablespace for table 'sysbench/sbtest2' that was exported from host 'zlm2' 21 2018-07-05T08:40:03.820441Z 10 [Note] InnoDB: Phase I - Update all pages 22 2018-07-05T08:40:03.859485Z 10 [Note] InnoDB: Sync to disk 23 2018-07-05T08:40:04.936351Z 10 [Note] InnoDB: Sync to disk - done! 24 2018-07-05T08:40:04.962775Z 10 [Note] InnoDB: Phase III - Flush changes to disk 25 2018-07-05T08:40:04.975519Z 10 [Note] InnoDB: Phase IV - Flush complete 26 2018-07-05T08:40:04.975722Z 10 [Note] InnoDB: `tt`.`sbtest2` autoinc value set to 100001 27 28 //The error log shows details of this import operation.
1 (root@localhost mysql3306.sock)[tt]>alter table sbtest2 discard tablespace; 2 Query OK, 0 rows affected (0.01 sec) 3 4 (root@localhost mysql3306.sock)[tt]>alter table sbtest2 discard tablespace; 5 Query OK, 0 rows affected, 1 warning (0.00 sec) 6 7 (root@localhost mysql3306.sock)[tt]>show warnings; 8 +---------+------+-----------------------------------------------------+ 9 | Level | Code | Message | 10 +---------+------+-----------------------------------------------------+ 11 | Warning | 1812 | InnoDB: Tablespace is missing for table tt/sbtest2. | 12 +---------+------+-----------------------------------------------------+ 13 1 row in set (0.00 sec) 14 15 2018-07-05T08:52:55.055225Z 11 [ERROR] InnoDB: Cannot delete tablespace 494 because it is not found in the tablespace memory cache. 16 2018-07-05T08:52:55.055226Z 11 [Warning] InnoDB: Cannot delete tablespace 494 in DISCARD TABLESPACE: Tablespace not found 17 18 //error log shows the ERROR & Warning because of the .ibd file has been deleted in first discard operation.
1 [root@zlm2 11:00:05 /data/mysql/mysql3306/data/sysbench] 2 #scp sbtest2.{ibd,cfg} zlm3:/data/mysql/mysql3306/data/tt/ 3 root@zlm3's password: 4 sbtest2.ibd 100% 29MB 29.0MB/s 00:01 5 sbtest2.cfg: No such file or directory 6 7 //Because of "unlock tables" operation,the .cfg file has gone now.
1 (root@localhost mysql3306.sock)[tt]>alter table sbtest2 import tablespace; 2 Query OK, 0 rows affected, 1 warning (2.34 sec) 3 4 (root@localhost mysql3306.sock)[tt]>show warnings; 5 +---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+ 6 | Level | Code | Message | 7 +---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+ 8 | Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory) Error opening './tt/sbtest2.cfg', will attempt to import without schema verification | 9 +---------+------+--------------------------------------------------------------------------------------------------------------------------------------------+ 10 1 row in set (0.00 sec) 11 12 //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.
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- MySQL replace函数怎么替换字符串语句 2020-03-09
- PHP访问MySQL查询超时怎么办 2020-03-09
- mysql登录时闪退 2020-02-27
- MySQL出现1067错误号 2020-02-27
- mysql7.x如何单独安装mysql 2020-02-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash