有什么方法可以显示`gunzip < database.sql.gz | 的进度吗?mysql ...`进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19598797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:13:57  来源:igfitidea点击:

Is there any way to show progress on a `gunzip < database.sql.gz | mysql ...` process?

mysqlsqlprogresssql-insertgunzip

提问by Ryan

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 processlistin 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)
  1. 获取数据库的未压缩文件大小并与我的本地数据库大小进行比较
  2. show processlist在 mysql 中运行以查看它当前插入的表(我当前的方法,但有些表很大,而且我的至少一个 db 只有一个巨大的表,所以大部分进程都卡在这个表中,留下这个选项少于有帮助)

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)

所有 db.sql.gz 文件都是标准的 gzipped mysqldumps,所以我认为我不能在转储中构建任何东西来给我更新。(但如果我遗漏了什么,我愿意接受)



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 mysqldumpexport or regular gunzip ... | mysqlimport (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 mysqldumpor alternative mysql branch requests.
  1. 提供有用且合理准确的进度(无论是视觉效果scp(首选!)还是通过可以轻松访问的简单进度数据库表)。
  2. 不破坏常规mysqldump导出或常规gunzip ... | mysql导入(对于可能不会使用您提出的任何内容的其他工程师)
  3. 不要让我的 DBA 心脏病发作——所以对特殊的mysqldump或替代的 mysql 分支请求保持轻松。

回答by Ali

You may use -v : Verbose mode (show progress) in your command, or there's another method using Pipe Viewer (pv) which shows the progress of the gzip, gunzip command as follows:

您可以在命令中使用 -v : 详细模式(显示进度),或者还有另一种使用管道查看器 ( pv) 的方法来显示 gzip、gunzip 命令的进度,如下所示:

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

This will output progress similar to scp:

这将输出类似于 scp 的进度:

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

You can also use Pipe Viewer to monitor mysqldump:

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

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

If you don't already have pv, you can install it with:

如果您还没有pv,您可以使用以下命令安装它:

yum install pv

or with macports

或使用 macports

sudo port install pv

or with homebrew

或自制

brew install pv

回答by banyek

I think I would perform a drop database before loading up the data, and after it happened I could run a continuous "du -sh" in the databases directory. If I know the size the original database directory (Why wouldn't I?) then I can use it as a progress monitor. Are the db's are droppable?

我想我会在加载数据之前执行一个删除数据库,在它发生之后我可以在数据库目录中运行一个连续的“du -sh”。如果我知道原始数据库目录的大小(我为什么不知道?),那么我可以将其用作进度监视器。db 是否可以删除?