moving InnoDB

本文介绍了一种在不中断服务的情况下,将InnoDB表从一台服务器迁移到另一台服务器的方法。此方法适用于恢复单个表、从生产环境复制到质量保证环境、以及重新划分数据库等场景。
Impossible - possible, moving InnoDB tables between servers
[url]http://www.mysqlperformanceblog.com/2009/06/08/impossible-possible-moving-innodb-tables-between-servers/[/url]

Impossible - possible, moving InnoDB tables between servers
Posted by Vadim

This is probably the feature I missed most from early days when I started to use InnoDB instead of MyISAM. Since that I figured out how to survive without it, but this is first question I hear from customers who migrated from MyISAM to InnoDB - can I just copy .ibd files from one server to another and answer “use mysqldump” is quite disappointed.
Jokes aside, I see real needs in this:
- when we need to restore only single table from backup (sometimes developers kill only single table, not whole database :) )
- to copy single table from production to QA environment. It may sound not so important, but I see needs in this quite often. QA boxes may have their own setup, not so powerful and with not enough space, but QA still needs to have some tables in fresh status.
- resharding databases, moving some shards from one server to another.

So long story short end - we made new mode for XtraBackup, now it can copy and prepare InnoDB/XtraDB tables, which later can be imported into XtraDB.

To be objective the process is still not so easy as with MyISAM tables when you just copy table.frm, table.MYD, table.MYI files, but so nice here - just can copy InnoDB tables in fully non-blocking mode, you do not need to shutdown neither source nor destination server (if destination server runs XtraDB).

In short, process looks like (ah, yes you also need innodb_file_table mode, which ones love, and ones hate)
1) do backup of specific tables on sources server with xtrabackup (server can run InnoDB or XtraDB, it does not matter)
2) do prepare of tables with –export options
3) create table on destination server with exactly the same CREATE TABLE statement as on source. (on destination you should have XtraDB with innodb_expand_import extension and with innodb_expand_import=1 setting)
4) run alter table IMPORTEDTABLE discard tablespace;
5) copy .exp and .ibd files to destination server
6) run alter table IMPORTEDTABLE import tablespace;
7) enjoy progress in error.log like:
InnoDB: import: extended import of test/img_out59
InnoDB: import: 3 indexes are detected.
InnoDB: Progress in %: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 done.

Some more information available on
http://www.percona.com/docs/wiki/percona-xtradb:patch:innodb_expand_import

If you want some internals: I expected the biggest problem with implementation would be merging insert buffer or handling undo records, stored in ibdata file, but it was easy - you just need to shutdown instance with innodb_fast_shutdown=1 (done in xtrabackup –prepare –export call). The more complex problem was that InnoDB stores pointers on root leafs of secondary indexes also in system tablespace. And that’s why we maintain .exp files - to keep information from system tablespace that related to exported table.

Both xtrabackup –export mode and XtraDB innodb_expand_import available only in source code for now, you can get them from Launchpad projects https://launchpad.net/percona-xtradb and https://launchpad.net/percona-xtrabackup. Binary releases will be ready as soon as we have done with testing of this feature. You are welcome to try!
把下列mysql语句转换成oracle语法,注意字符转换,并在行首添加一列sid自增主键 ,行末添加sc varchar(100) '数据来源' 和 dt varchar(200) '入库时间' 两个字段以及添加注释 如果含有'_op'字段,则转换为 op,返还语句即可 不需要说明,先写建表语句和表注释 其次序列 然后触发器 -- gm.scm_dom_trade_moving_warehouse_confirm definition CREATE TABLE `ods_dom_td_mv_wh_cf_agr ` ( `id` varchar(36) NOT NULL, `create_by` varchar(50) DEFAULT NULL COMMENT '创建人', `create_time` datetime DEFAULT NULL COMMENT '创建日期', `update_by` varchar(50) DEFAULT NULL COMMENT '更新人', `update_time` datetime DEFAULT NULL COMMENT '更新日期', `sys_org_code` varchar(64) DEFAULT NULL COMMENT '所属部门', `moving_warehouse_confirm_no` varchar(50) DEFAULT NULL COMMENT '移库确认单号', `moving_warehouse_notice_id` varchar(50) DEFAULT NULL COMMENT '移库通知单id', `moving_warehouse_notice_no` varchar(50) DEFAULT NULL COMMENT '移库通知单号', `moving_mode` varchar(4) DEFAULT NULL COMMENT '移库方式', `moving_warehouse_notice_date` date DEFAULT NULL COMMENT '申请移库日期', `more_or_less` decimal(18,4) DEFAULT NULL COMMENT '短溢装', `moving_warehouse_start` date DEFAULT NULL COMMENT '移库起始日期', `moving_warehouse_end` date DEFAULT NULL COMMENT '移库截止日期', `total_moving_num` decimal(18,4) DEFAULT NULL COMMENT '移库总数量', `actual_moving_num` decimal(18,4) DEFAULT NULL COMMENT '实际移库总数量', `status` varchar(32) DEFAULT NULL COMMENT '状态', `remark` varchar(500) DEFAULT NULL COMMENT '备注', `use_seal` varchar(4) DEFAULT NULL COMMENT '是否用印', `use_seal_info` text COMMENT '用印信息', `files` text COMMENT '附件', `delete_flag` varchar(4) DEFAULT NULL COMMENT '删除', `instance_id` varchar(100) DEFAULT NULL COMMENT '审批流id', `create_user_name` varchar(100) DEFAULT NULL COMMENT '创建人姓名', `confirm_time` datetime DEFAULT NULL COMMENT '确认时间', `_op` varchar(4) DEFAULT 'r' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; comment '粮食移库确认单 '
08-23
把下列mysql语句转换成oracle语法,注意字符转换,并在行首添加一列sid自增主键 ,行末添加sc varchar(100) '数据来源' 和 dt varchar(200) '入库时间' 两个字段以及添加注释 如果含有'_op'字段,则转换为 op,返还语句即可 不需要说明,先写建表语句和表注释 其次序列 然后触发器 -- gm.scm_dom_trade_moving_warehouse_confirm_product definition CREATE TABLE `ods_dom_td_mv_wh_cf_pd_agr ` ( `id` varchar(36) NOT NULL, `create_by` varchar(50) DEFAULT NULL COMMENT '创建人', `create_time` datetime DEFAULT NULL COMMENT '创建日期', `update_by` varchar(50) DEFAULT NULL COMMENT '更新人', `update_time` datetime DEFAULT NULL COMMENT '更新日期', `sys_org_code` varchar(64) DEFAULT NULL COMMENT '所属部门', `main_id` varchar(50) DEFAULT NULL COMMENT '主表id', `moving_warehouse_confirm_no` varchar(50) DEFAULT NULL COMMENT '移库确认单号', `moving_warehouse_notice_product_id` varchar(50) DEFAULT NULL COMMENT '移库通知单明细id', `product_name` varchar(100) DEFAULT NULL COMMENT '品名', `product_no` varchar(50) DEFAULT NULL COMMENT '产品编码', `spec` varchar(100) DEFAULT NULL COMMENT '规格', `inv_id` varchar(50) DEFAULT NULL COMMENT '库存id', `inv_num` decimal(18,4) DEFAULT NULL COMMENT '库存数量', `actual_moving_num` decimal(18,4) DEFAULT NULL COMMENT '实际移库数量', `stockin_id` varchar(50) DEFAULT NULL COMMENT '入库单id', `stockin_no` varchar(50) DEFAULT NULL COMMENT '入库单号', `existing_warehouse_id` varchar(50) DEFAULT NULL COMMENT '现存仓库id', `existing_warehouse_name` varchar(100) DEFAULT NULL COMMENT '现存仓库', `moving_warehouse_id` varchar(50) DEFAULT NULL COMMENT '移库仓库id', `moving_warehouse_name` varchar(100) DEFAULT NULL COMMENT '移库仓库', `year` varchar(10) DEFAULT NULL COMMENT '年份', `origin_place` varchar(32) DEFAULT NULL COMMENT '产地', `pur_contract_no` varchar(50) DEFAULT NULL COMMENT '采购合同号', `moving_num` decimal(18,4) DEFAULT NULL COMMENT '移库数量', `pur_contract_id` varchar(50) DEFAULT NULL COMMENT '采购合同id', `_op` varchar(4) DEFAULT 'r' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; comment '粮食移库确认单 '
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值