Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large file of MySQL insert statements that I need to submit to a database.

Normally I would just "cat $FILE|mysql -u$USER -p$PASS database".

The problem is, that the file occasionally has errors in it, causing this command to fail.

It is safe for me to skip the lines with errors, but undesirable to re-submit the same data more than once.

  • what is the best way for me to parse this file and submit it to the database?

I have written a bash script which works - except when the file is big it takes way too long (it deletes each line after it processes it so that interrupting the script will not cause data to be re-submitted again, which is a slow process)

share|improve this question
up vote 2 down vote accepted

Why don't you just provide the --force option to mysql and use your cat | mysql ....

--force, -f
  Continue even if an SQL error occurs.
share|improve this answer
perfect! That's what I'm looking for. Thanks. – Brent Sep 25 '09 at 18:54

I believe mysql --force tells the client to continue after errors

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.