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

2012年(21)

2011年(28)

2010年(50)

分类: Mysql/postgreSQL

2011-05-11 14:52:52

今天在对数据库进行备份时,发现在生产机器上执行mysqldump --master-data dbname>/tmp/dbname.sql后,/tmp下dbname.sql生成了,但一直是0 KB,等了一会,还是0 KB。此时网站已经不能写入了,赶紧停止备份。由于生产机用的plugin innodb,难道是这个原因?于是到另外一台空机器上做测试,发现同样的参数和环境,很快就备份出来了。打开mysqldump参数查看,如下:
  1. --master-data[=#] This causes the binary log position and filename to be
  2.                     appended to the output. If equal to 1, will print it as a
  3.                     CHANGE MASTER command; if equal to 2, that command will
  4.                     be prefixed with a comment symbol. This option will turn
  5.                     --lock-all-tables on, unless --single-transaction is
  6.                     specified too (in which case a global read lock is only
  7.                     taken a short time at the beginning of the dump; don
默认参数就是1.  这个参数会打开--lock-all-tables。这么看来,前面一直是0 KB的时间里,是MYSQLDUMP程序在等待别的链接释放锁,直到对所有的表都加了X锁后,才开始备份的。这就解释了为什么测试机没问题,而生产机需要等待了。

然后又set sutocommit=0,做了试验,验证了前面的判断。

阅读(1312) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~