加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

通过数据库拆分具有多个数据库的mysqldump文件

发布时间:2020-12-12 16:44:21 所属栏目:MsSql教程 来源:网络整理
导读:我有一个 mysqldump文件的多个数据库(5).数据库中的一个需要很长时间才能加载,有没有办法通过数据库拆分mysqldump文件,或者只是告诉mysql只加载一个指定的数据库? 马尼什 解决方法 这个Perl脚本应该做的伎俩. #!/usr/bin/perl -w## splitmysqldump - split m
我有一个 mysqldump文件的多个数据库(5).数据库中的一个需要很长时间才能加载,有没有办法通过数据库拆分mysqldump文件,或者只是告诉mysql只加载一个指定的数据库?

马尼什

解决方法

这个Perl脚本应该做的伎俩.
#!/usr/bin/perl -w
#
# splitmysqldump - split mysqldump file into per-database dump files.

use strict;
use warnings;

my $dbfile;
my $dbname = q{};
my $header = q{};

while (<>) {

    # Beginning of a new database section:
    # close currently open file and start a new one
    if (m/-- Current Database: `([-w]+)`/) {
    if (defined $dbfile && tell $dbfile != -1) {
        close $dbfile or die "Could not close file!"
    } 
    $dbname = $1;
    open $dbfile,">>","$1_dump.sql" or die "Could not create file!";
    print $dbfile $header;
    print "Writing file $1_dump.sql ...n";
    }

    if (defined $dbfile && tell $dbfile != -1) {
    print $dbfile $_;
    }

    # Catch dump file header in the beginning
    # to be printed to each separate dump file.  
    if (! $dbname) { $header .= $_; }
}
close $dbfile or die "Could not close file!"

对于包含所有数据库的转储文件运行此操作

./splitmysqldump < all_databases.sql

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读