I'm trying to dump and import some data from a MySQL (5.7) database.

Running the command

mysqldump --tab=/mysqldump mydatabase

I'm able to get a .sql and .txt file for each table.

How can I import all the files/tables using mysqlimport in a single command?

I have tried mysqlimport mydatabase /mysqldump but it does not work.



Do not use --tab option, use general syntax mysqldump [options] db_name tbl_name ... > dump.sql instead. You'll get an ordinary sql-script that can be executed via CLI-client mysql such way:

mysql -u dbauser -p < /path/to/dump.sql 

Anyway to import different dumpfiles you have to use some shell script that build the list of files in the given directory and then proceed that list one by one like that:

for file in /path/to/*.txt
   mysqlimport database $file
  • Thanks for your reply. Are there any specific reasons I should not use --tab?
    – Sig
    Aug 8 '17 at 2:34
  • @macsig Tab- or comma-separated export is useful for cross-platform data migration but if you want to migrate data from one mysql server to another export to the sql-script is preferrable. At least because you need no access to the server's filesystem via ftp/scp/sftp as well as shell access to run mysqlimport. Common tools like phpmysqladmin or mysqlbench or heidisql can execute script without complications.
    – Kondybas
    Aug 8 '17 at 17:17
  • When the file is big, dump.sql is too slow. Loading from txt file could be much faster.
    – GoYun.Info
    Oct 27 '21 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.