Q:

Search recursively for all files with a .sql extension and pass them to mysql as argument

Given:
Directory tree that contains files with .sql extension.
Requred
Find them all recursively and pass found files one by one to mysql client as:
mysql < ./dir/subdir/subsubdir/schema.sql
My feeble attempt
find . -name '*.sql' | xargs mysql
Results in:
ERROR 1049 (42000): Unknown database './dir/subdir/subsubdir/schema.sql'

Question
How to do it right?
Thanks!

A:

I believe this will work
find . -type f -name '*.sql' -exec bash -c 'cat '{}' | mysql' \;

Basically the above finds all files ending in .sql (I put the -type f in there just in case there are any directories that end in .sql).  For each file found, find runs the exec command.  The exec runs a bash sub-shell that cats the file and pipes that to the mysql program.
Hope this helps.

