Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.