1

I have a large sql dump that has 1 insert statement per line. I want to be able to pipe this to xargs so that I can slow down the writes. Basically I want to execute a number of lines, sleep, then continue to execute and so forth.

I current have this:

cat file.sql | xargs -n50 -d "\n" sh -c '(echo "$@" | mysql db_name); sleep 10'

But the problem is that I believe somewhere in the file, there's a \n that's causing sql to break. I'm using INSERT IGNORE and this is resulting to missing rows.

I don't want to go through the file and fix the \n. Is there a way to use line instead of \n?

I've tried:

cat file.sql | xargs -L 50 sh -c '(echo "$@" | mysql db_name); sleep 10'

but I'm getting:

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

1 Answer 1

1

I would actually just modify the SQL. MySQL has a SLEEP function you can select from. The following will inject a 10 second delay every 50 lines... And then just pipe that into the mysql command.

awk '{print} NR%50==0 {print "SELECT SLEEP(10);"}' file.sql | mysql db_name
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .