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

前端 未结 18 1535
孤城傲影
孤城傲影 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:23

    You say that you don't have access to the second server. But if you have shell access to the first server, where the tables are, you can split your dump by table:

    for T in `mysql -N -B -e 'show tables from dbname'`; \
       do echo $T; \
       mysqldump [connecting_options] dbname $T \
       | gzip -c > dbname_$T.dump.gz ; \
       done

    This will create a gzip file for each table.

    Another way of splitting the output of mysqldump in separate files is using the --tab option.

    mysqldump [connecting options] --tab=directory_name dbname 

    where directory_name is the name of an empty directory. This command creates a .sql file for each table, containing the CREATE TABLE statement, and a .txt file, containing the data, to be restored using LOAD DATA INFILE. I am not sure if phpMyAdmin can handle these files with your particular restriction, though.

提交回复
热议问题