Mysql – How tomport all the files in a directory with a single command using thesqlimport

MySQLmysqldump

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.

Best Answer

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
####