0

I am trying to import a series of .SQL files which map one file per DB object into mysql without calling mysql 50 times, something like:

mysql -u root < cat schema/db1/*.sql

This isn't working as "cat" is not a directory -- how would I accomplish this -- and why isn't what I have working? What am I not understanding about linux command piping???

EDIT | The database is created by the SQL file so this doesn't work either:

cat bridge_access/*.sql | mysql -u root bridge_access
  • What does your comment "as 'cat' is not a directory" mean? Is that supposed to be related to an error message you're seeing? If so, could you edit your message to include it. If you just do the cat part do you see all the output you expect? – Eric Renouf Aug 26 '15 at 17:43
3

The command you're trying is trying to treat cat as a file, shoving it's contents into mysql's STDIN. Instead, you need the results of the cat command shoved into STDIN, which can be done a couple different ways. The way I would do it would be to pipe the output of cat into mysql:

$ cat schema/db1/*.sql | mysql -u root

Equally validly, you can use:

$ mysql -u root < `cat schema/db1/*.sql`
  • Sorry, but #2 is not going to work. The closest would be mysql -u root < <(cat schema/db1/*.sql). – sborsky Aug 26 '15 at 17:50

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.