2012-01-18 51 views
5

我最近决定公司通过我得到我的主机切换,让我的老数据库移动到我的新的数据库,我一直在试图运行这个命令:mysqldump的部分数据库

mysqldump --host=ipaddress --user=username --password=password db_name table_name | mysql -u username -ppassword -h new_url new_db_name 

,这似乎工作正常..但因为我的数据库是如此惊人的巨大,我会得到时间在我的表中错误。所以我想知道是否有任何简单的方法在我桌子的一部分上做mysqldump

我将承担的工作流程将是这个样子:

create temp_table 
move rows from old_table where id>2,500,000 into temp_table 
some how dump the temp table into the new db's table (which has the same name as old_table) 

但我不完全知道如何做这些步骤。

+0

不知道它是否能解决您的问题,但请查看http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html处的'--quick'选项。说它对大型表格很有用。 – 2012-01-18 17:56:37

回答

5

mysqldump命令的末尾加上这个--where="id>2500000"MySQL 5.1 Reference Manual

在你的情况mysqldump命令会是什么样子

mysqldump --host=ipaddress \ 
    --user=username \ 
    --password=password \ 
    db_name table_name \ 
    --where="id>2500000 

如果你倾倒的两倍。第二个转储将包含表创建信息。但下一次只想添加新行。因此,对于第二次转储,请在mysqldump命令行中添加--no-create-info选项。

+0

事实证明,这个命令实际上用“id> 2500000”的行代替了我的表。所以我最终做的是将它们全部移到一个新表中,并将这两个表与[这篇文章]合并(http://stackoverflow.com/questions/725556/how-can-i-merge-two-mysql-表) – BananaNeil 2012-01-19 07:35:39

+0

@BananaNeil它可能发生,如果你的转储包含第二次只转储数据在mysql命令行上添加'--no-create-info'选项。 – 2012-01-19 11:53:26

2

我为这项工作开发了一个工具。这就是所谓的mysqlsuperdump并且可以在这里找到:

https://github.com/hgfischer/mysqlsuperdump

有了它,你可以speciffy每个表的完整的“WHERE”条款,所以它可以为每个表指定不同的规则。

您也可以用转储中的每个表替换每列的值。例如,当您想要导出数据库转储以用于开发环境时,这很有用。