12
返回列表 发新帖
楼主: xiaoxiongg

用cp能克隆数据库么

[复制链接]
论坛徽章:
10
2011新春纪念徽章
日期:2011-02-18 11:43:362013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:08:15双黄蛋
日期:2012-04-18 13:03:23蛋疼蛋
日期:2012-02-14 09:01:14复活蛋
日期:2012-02-01 10:04:16双黄蛋
日期:2012-01-16 14:47:262012新春纪念徽章
日期:2012-01-04 11:53:29ITPUB十周年纪念徽章
日期:2011-11-01 16:23:26优秀写手
日期:2013-12-18 09:29:12
11#
发表于 2012-3-13 09:04 | 只看该作者
如果用percona server的话有个方法可以在服务器之间移动ibd文件

  1. xtrabackup  --defaults-file=/etc/my.cnf --backup --tables=test.t1 --target-dir=/data/tmp/

  2. xtrabackup: tables regcomp(test.t1): Success
  3. xtrabackup version 1.6.5 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (revision id: 328)
  4. xtrabackup: uses posix_fadvise().
  5. xtrabackup: cd to /var/lib/mysql
  6. xtrabackup: Target instance is assumed as followings.
  7. xtrabackup:   innodb_data_home_dir = ./
  8. xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
  9. xtrabackup:   innodb_log_group_home_dir = ./
  10. xtrabackup:   innodb_log_files_in_group = 2
  11. xtrabackup:   innodb_log_file_size = 5242880
  12. 120312 16:38:22  InnoDB: Warning: allocated tablespace 10, old maximum was 9
  13. >> log scanned up to (1601674)
  14. [01] Copying ./ibdata1
  15.      to /data/tmp//ibdata1
  16. [01]        ...done
  17. [01] Copying ./test/t1.ibd
  18.      to /data/tmp//test/t1.ibd
  19. [01]        ...done
  20. xtrabackup: The latest check point (for incremental): '1601674'
  21. >> log scanned up to (1601674)
  22. xtrabackup: Stopping log copying thread.
  23. xtrabackup: Transaction log of lsn (1601674) to (1601674) was copied.


  24. xtrabackup  --defaults-file=/etc/my.cnf --prepare --export --target-dir=/data/tmp

  25. xtrabackup version 1.6.5 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (r                                                                                                 evision id: 328)
  26. xtrabackup: cd to /data/tmp
  27. xtrabackup: This target seems to be not prepared yet.
  28. xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(1601674)
  29. xtrabackup: Temporary instance for recovery is set as followings.
  30. xtrabackup:   innodb_data_home_dir = ./
  31. xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
  32. xtrabackup:   innodb_log_group_home_dir = ./
  33. xtrabackup:   innodb_log_files_in_group = 1
  34. xtrabackup:   innodb_log_file_size = 2097152
  35. xtrabackup: Starting InnoDB instance for recovery.
  36. xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter                                                                                                 )
  37. InnoDB: The InnoDB memory heap is disabled
  38. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  39. InnoDB: Compressed tables use zlib 1.2.3
  40. InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io                                                                                                 _threads and innodb_write_io_threads instead
  41. 120312 16:41:17  InnoDB: Initializing buffer pool, size = 100.0M
  42. 120312 16:41:17  InnoDB: Completed initialization of buffer pool
  43. 120312 16:41:17  InnoDB: highest supported file format is Barracuda.
  44. InnoDB: The log sequence number in ibdata files does not match
  45. InnoDB: the log sequence number in the ib_logfiles!
  46. 120312 16:41:17  InnoDB: Database was not shut down normally!
  47. InnoDB: Starting crash recovery.
  48. InnoDB: Reading tablespace information from the .ibd files...
  49. 120312 16:41:17 Percona XtraDB (http://www.percona.com) 1.0.17-12.5 started; log                                                                                                  sequence number 1601674
  50. xtrabackup: export option is specified.
  51. xtrabackup: export metadata of table 'test/t1' to file `./test/t1.exp` (1 indexe                                                                                                 s)
  52. xtrabackup:     name=GEN_CLUST_INDEX, id.low=16, page=3

  53. [notice (again)]
  54.   If you use binary log and don't use any hack of group commit,
  55.   the binary log position seems to be:

  56. xtrabackup: starting shutdown with innodb_fast_shutdown = 0
  57. 120312 16:41:17  InnoDB: Starting shutdown...
  58. 120312 16:41:17  InnoDB: Shutdown completed; log sequence number 1601674

复制代码
在需要导入数据的服务器

  1. mysql> set global innodb_import_table_from_xtrabackup=1;
复制代码
创建table

  1. mysql> create table t1 (id int)engine=innodb;
复制代码
删除表空间

  1. mysql> alter table t1 discard tablespace;
复制代码
拷贝ibd和exp文件到指定位置
cp t1.* /var/lib/mysql/test/

  1. mysql> alter table t1 import tablespace;
复制代码
另外数据可能需要重启mysql才能看到!

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表