MySQL mysqldump 压缩

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9887637/
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 12:44:04  来源:igfitidea点击:

mysqldump compression

mysql

提问by Mark Belli

I am trying to understand how mysqldump works:

我试图了解 mysqldump 是如何工作的:

if I execute mysqldump on my pc and connect to a remote server:

如果我在我的电脑上执行 mysqldump 并连接到远程服务器:

mysqldump -u mark -h 34.32.23.23 -pxxx  --quick | gzip > dump.sql.gz

will the server compress it and send it over to me as gzip or will my computer receive all the data first and then compress it?

服务器会压缩它并将其作为gzip发送给我还是我的计算机会先接收所有数据然后再压缩它?

Because I have a very large remote db to export, and I would like to know the fastest way to do it over a network!

因为我有一个非常大的远程数据库要导出,我想知道通过网络完成它的最快方法!

回答by ajreal

You should make use of ssh + scp,
because the dump on localhost is faster,
and you only need to scp over the gzip (lesser network overhead)

您应该使用 ssh + scp,
因为 localhost 上的转储速度更快,
并且您只需要通过 gzip scp(较少的网络开销)

likely you can do this

可能你可以这样做

ssh [email protected] "mysqldump -u mark -h localhost -pxxx --quick | gzip > /tmp/dump.sql.gz"

scp [email protected]:/tmp/dump.sql.gz .

(optional directory of /tmp, should be change to whatever directory you comfortable with)

(/tmp 的可选目录,应更改为您喜欢的任何目录)

回答by Dojo

This is how I do it:

这就是我的做法:

Do a partial export using SELECT INTO OUTFILEand create the files on the same server.

使用SELECT INTO OUTFILE并在同一服务器上创建文件进行部分导出。

If your table contains 10 million rows. Do a partial export of 1 million rows at a time, each time in a separate file.

如果您的表包含 1000 万行。一次部分导出 100 万行,每次都在一个单独的文件中。

Once the 1st file is ready you can compress and transfer it. In the meantime MySQL can continue exporting data to the next file.

一旦第一个文件准备好,您就可以压缩和传输它。与此同时,MySQL 可以继续将数据导出到下一个文件。

On the other server you can start loading the file into the new database.

在另一台服务器上,您可以开始将文件加载到新数据库中。

BTW, lot of this can be scripted.

顺便说一句,很多都可以编写脚本。