简体   繁体   English

分割.sql备份文件

[英]Split .sql Backup File

I download backup of my database every week from my hosting. 我每周从托管服务器下载数据库备份。 It generates a .sql file that currently has approximately 800mb. 它会生成一个.sql文件,当前大小约为800mb。 This .sql file contains 44 tables. 该.sql文件包含44个表。

Is there any way, through some software that I can split the .sql file with all the tables, in order to individually export each table? 有什么办法可以通过某些软件拆分所有表的.sql文件,以便分别导出每个表?

So, if I had to reset the backup at some point, I would do it by table, and I would not have to do to the entire database. 因此,如果必须在某个时候重置备份,则可以按表进行备份,而不必对整个数据库进行备份。

I wouldn't split it after, if you have server access yourself over ssh you could (and in my eyes should) do something like this : 之后,我不会拆分它,如果您可以通过ssh访问服务器,则可以(并且在我看来)可以执行以下操作:

for table in `mysql -u [USER] -p[PASSWORD] -N -B -e 'show tables from [DATABASE]'`;
do
    mysqldump --skip-comments --compact -u [USER] -p[PASSWORD] [DATABASE] $table  > $table.sql 
    && tar -czvf $table.tar.gz $table && rm $table.sql
done;

Which should generate one file per table. 每个表应生成一个文件。 Then just .gz whatever directory you put the files in and you should have your backup in the way you want it. 然后,将文件放置在.gz中的任何目录中,都应该以所需的方式进行备份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM