English 中文(简体)
MySQL转储的导入还有多远?
原标题:How far along is the importation of my MySQL dump?
  • 时间:2012-05-25 16:54:58
  •  标签:
  • mysql

在我的公司,我们偶尔会导入大型客户MySQL数据库(40GB+),这些数据库可能需要一天多的时间才能加载到我们的开发人员机器上。虽然我们接受这个加载时间,因为它是在后台完成的,但我们缺乏任何可靠的能力来估计导入何时完成。这让我们无法安排一个合适的时间来采取行动。这就像等待有线电视的人出现。

现在我最好的策略是使用快速的show tables命令来查看已加载的表的百分比。然而,由于桌子大小彼此之间以及每个客户之间都有很大差异,这甚至不太可靠。

有人有好的技术或工具可以用来获得MySQL导入进度的可靠百分比吗

最佳回答

您可以使用pv命令,通过管道将转储传输到mysql

pv -i 1 -p -t -e /path/to/sql/dump | mysql -u USERNAME -p DATABASE_NAME

在导入过程中,它将根据IO吞吐量向您显示进度条。(如所见此处。)

问题回答

HeidiSql会告诉你到目前为止已经加载了多少GB,这在试图计算还需要加载多少GB时非常有用。

您还可以在源数据库上执行show processlist,以查看导出到特定表的距离(通过自动递增ID)。Eric提出了一个很好的观点,即您可以监视数据库数据目录的大小与源数据库的大小之比。

我发现在加速转储/导入方面有一个有用的方法,那就是按表执行,然后同时运行多个mysql转储——本质上是对进程进行多线程处理。我通常一次做大约4个单独的转储/恢复。最佳数量将取决于您的硬件和磁盘容量。

一个非常简单的例子给你一个想法:

mysqldump dbname table1 table2 table3 | mysql -h host &
mysqldump dbname table4 table5 table6 | mysql -h host &
mysqldump dbname table7 table8 table9 | mysql -h host &




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...