mysql …` process?

问题描述 投票:42回答:2

Once a week I need to run a giant database update into my local development environment like so:

$ gunzip < /path/to/database1.sql.gz | mysql -uUSER -p database1 &
$ gunzip < /path/to/database2.sql.gz | mysql -uUSER -p database2 &
$ gunzip < /path/to/database3.sql.gz | mysql -uUSER -p database3 &

I try to run these overnight since it can take several hours to complete.

Can you help me come up with a way to show progress on these tasks?

Here are some guesses:

  1. Get the uncompressed filesize of the db and compare with my local db size
  2. Run show processlist in mysql to see what table it's currently inserting (my current method, but some tables are huge, and at least one db of mine only has one giant table so the bulk of the process is stuck in this table, leaving this option less than helpful)

All of the db.sql.gz files are standard gzipped mysqldumps, so I don't think I can build anything into the dumps to give me an update. (But I'm open to that if I'm missing something)


Bounty Rules

Answers must:

  1. Provide useful and reasonably accurate progress (either visual like scp (preferred!) or through a simple progress database table that could be accessed easily).
  2. Not break regular mysqldump export or regular gunzip ... | mysql import (for other engineers who may not use whatever you come up with)
  3. Not give my DBA a heart attack — so stay easy on special mysqldump or alternative mysql branch requests.
mysql sql progress sql-insert gunzip
2个回答
118
投票

你可以在命令中使用-v : Verbose模式(显示进度),或者还有一种方法使用Pipe Viewer (pv),显示gzip、gunzip命令的进度如下。

$ pv database1.sql.gz | gunzip | mysql -u root -p database1

mysql -uUSER -p database1 & $ gunzip <

$ pv database1.sql.gz | gunzip | mysql -uroot -p database1
  593MiB 1:00:33 [ 225kiB/s] [====================>              ] 58% ETA 0:42:25

你也可以使用Pipe Viewer来监控mysqldump。

mysqldump -uroot -p database1 | pv | gzip -9 > database1.sql.gz

如果你还没有 pv,你可以安装它。

yum install pv

或者用macports

sudo port install pv

或用自制

brew install pv

2
投票

我想我会在加载数据之前执行drop数据库,发生后我可以在databases目录下连续运行 "du -sh"。如果我知道原始数据库目录的大小(为什么不知道?db's是可滴的吗?

© www.soinside.com 2019 - 2024. All rights reserved.