Wednesday, May 15, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1847  / 3 Years ago, fri, june 11, 2021, 10:36:36

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!


More From » bash

 Answers
0

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.


[#6767] Saturday, June 12, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
howesale

Total Points: 224
Total Questions: 117
Total Answers: 116

Location: Nauru
Member since Thu, May 18, 2023
1 Year ago
;