2

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.

Thanks.

2

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:

#!/bin/sh
for file in /path/to/*.txt
do 
   mysqlimport database $file
done
####
  • 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

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.