How can I import multiple .sql files into MySQL?
Andrew Mclaughlin
In my folder, I have a lot of *.sql files... How via one command I can import them?
For example; is something like this possible?
mysql -u root -p db_development < *.sqlIf not, how can I import every .sql file into MySQL?
2 Answers
This is the best one-line I know:
for SQL in *.sql; do DB=${SQL/\.sql/}; mysql $DB < $SQL; doneor with password:
for SQL in *.sql; do DB=${SQL/\.sql/}; mysql -u user --password=11111 $DB < $SQL; done"Warning: the password is plain text so visible when using 'ps'.
6cat *.sql | mysql -u root -p db_developmentThis will ask one time for the password.
If the statements belong to different databases, insert a USE databasename; at the top of all .sql files.