Chinaunix首页 | 论坛 | 博客
  • 博客访问: 489816
  • 博文数量: 99
  • 博客积分: 3621
  • 博客等级: 中校
  • 技术积分: 1089
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-22 16:29
文章存档

2012年(21)

2011年(28)

2010年(50)

分类: 数据库开发技术

2012-05-22 10:14:32

pt-online-schema-change使用

点击(此处)折叠或打开

  1. #install percona-toolkit-2.1.1-1
  2. #need rpm packages below,
  3. #could search them at: http://rpm.pbone.net/
  4. #another web site: http://rpmfind.net/linux/RPM/index.html

  5. mysql55-libs-5.5.12-1.ius.el5.x86_64.rpm
  6. percona-toolkit-2.1.1-1.noarch.rpm
  7. perl-TermReadKey-2.30-3.el6.rfx.x86_64.rpm
  8. MySQL-python-1.2.3-3.fc15.x86_64.rpm
  9. perl-DBD-MySQL-4.014-1.el6.rfx.x86_64.rpm
  10. perl-Test-Simple-0.98-1.el6.rfx.noarch.rpm
  11. MySQL-shared-compat-5.6.5_m8-1.el6.x86_64.rpm
  12. perl-DBI-1.620-1.el6.rfx.x86_64.rpm
  13. perl-Time-HiRes-1.9724-1.el6.rfx.x86_64.rpm


  14. #create new tables with new schema,and import table rows.
  15. mysql> insert into t1(id,k,c,pad,test) select id,k,c,pad,'this is a test' from sbtest;
  16. Query OK, 5000000 rows affected (3 min 32.50 sec)

  17. #use pt-online-schema-change
  18. [root@***** DBD-mysql-4.020]# time pt-online-schema-change --alter "ADD COLUMN c2 INT default 100" D=sbtest,t=sbtest --host=localhost --password=ondemand --user=root --execute
  19. Altering `sbtest`.`sbtest`...
  20. Creating new table...
  21. Created new table sbtest._sbtest_new OK.
  22. Altering new table...
  23. Altered `sbtest`.`_sbtest_new` OK.
  24. Creating triggers...
  25. Created triggers OK.
  26. Copying approximately 5000071 rows...
  27. Copying `sbtest`.`sbtest`: 20% 01:54 remain
  28. Copying `sbtest`.`sbtest`: 37% 01:38 remain
  29. Copying `sbtest`.`sbtest`: 46% 01:44 remain
  30. Copying `sbtest`.`sbtest`: 56% 01:33 remain
  31. Copying `sbtest`.`sbtest`: 64% 01:21 remain
  32. Copying `sbtest`.`sbtest`: 73% 01:05 remain
  33. Copying `sbtest`.`sbtest`: 82% 00:46 remain
  34. Copying `sbtest`.`sbtest`: 90% 00:25 remain
  35. Copying `sbtest`.`sbtest`: 94% 00:14 remain
  36. Copying `sbtest`.`sbtest`: 97% 00:08 remain
  37. Copying `sbtest`.`sbtest`: 99% 00:00 remain
  38. Copied rows OK.
  39. Swapping tables...
  40. Swapped original and new tables OK.
  41. Dropping old table...
  42. Dropped old table `sbtest`.`_sbtest_old` OK.
  43. Dropping triggers...
  44. Dropped triggers OK.
  45. Successfully altered `sbtest`.`sbtest`.

  46. real 5m49.554s
  47. user 0m0.741s
  48. sys 0m0.100s

  49. #bug list:
  50. https://bugs.launchpad.net/percona-toolkit/+bugs?field.tag=pt-online-schema-change#show_id=true&show_tag=false&show_reporter=false&show_importance=true&show_assignee=false&show_date_last_updated=false&show_datecreated=false&show_targetname=true&show_heat=true&show_milestone_name=false&show_status=true&batch_key=%5B%22-importance%22%2Cnull%2Ctrue%2C0%5D

  51. #detail:
  52. http://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html
在修改表结构过程中,可以对原表进行各种操作。注意bugs列表里的问题。
官方的这句话,值得关注:
pt-online-schema-change modifies data and structures. You should be careful with it, and test it before using it in production. You should also ensure that you have recoverable backups before using this tool.
 
安装完所有rpm包之后,可能出现链接数据错误
#运行报错
/usr/bin/perl: symbol lookup error: /usr/local/lib64/perl5/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init
#解决办法,重新安装DBD-mysql
mkdir /tmp/mysql-static
cp /usr/lib64/mysql/*.a /tmp/mysql-static
perl Makefile.PL --libs="-L/tmp/mysql-static -lmysqlclient"
make
make install
rm -rf /tmp/mysql-static
阅读(4529) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

yuanxb19852012-08-20 15:16:26

就这也好意思写出来

9094133352012-05-22 11:41:49

DBD需要软连接的原因“the mysql distribution I used is statically linked. So when DB:mysql is installed, it needs to be compiled with those static libraries:”