How do I split the output from mysqldump into smaller files?

前端 未结 18 1522
孤城傲影
孤城傲影 2020-11-27 13:50

I need to move entire tables from one MySQL database to another. I don\'t have full access to the second one, only phpMyAdmin access. I can only upload (compressed) sql file

18条回答
  •  孤城傲影
    2020-11-27 14:11

    You can split existent file by AWK. It's very quik and simple

    Let's split table dump by 'tables' :

    cat dump.sql | awk 'BEGIN {output = "comments"; }
    $data ~ /^CREATE TABLE/ {close(output); output = substr($3,2,length($3)-2); }
    { print $data >> output }';
    

    Or you can split dump by 'database'

    cat backup.sql | awk 'BEGIN {output="comments";} $data ~ /Current Database/ {close(output);output=$4;} {print $data>>output}';
    

提交回复
热议问题