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
1
  • 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? Commented Aug 26, 2015 at 17:43

1 Answer 1

4

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`
1
  • Sorry, but #2 is not going to work. The closest would be mysql -u root < <(cat schema/db1/*.sql). Commented Aug 26, 2015 at 17:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.