Ignore mysql error while executing bulk statements

Sometimes when running MySQL in batch mode, it requires to ignore some mysql errors which pops in between.

As an example, we can consider a scenerio where thousands of inserts required to be done and the statements are saved in a file, suppose in indata.sql. But it may be the case that some records are already there in database which you’re trying to insert. MySQL will show error something like below and exit:

ERROR 1062 (23000) at line 6: Duplicate entry 'blablabla' for key 2

So, to ignore the error and keep the insertion process running, you need to supply extra command line argument “-f” while execution:

# mysql -f -u root -p dbname < indata.sql

MySQL will certainly show the errors but not halt, instead keep execution of next statements.

Bookmark and Share

2 Responses to “Ignore mysql error while executing bulk statements”

  1. [...] Related posts in this blog on MySQL: 1. Setup MySQL Cluster in RedHat based Linux 2. Setup Multiple MySQL server instances in a single Linux Server. 3. Optimize a large installation of MySQL. 4. Fix MySQL running slow without any known reason. 5. Ignore MySQL error coming while executing bulk statements. [...]

  2. Fed up with getting low amounts of useless traffic for your site? Well i want to tell you about a brand new underground tactic that produces me personally $900 every day on 100% AUTOPILOT. I could be here all day and going into detail but why dont you simply check their site out? There is really a great video that explains everything. So if your seriously interested in making hassle-free money this is the site for you. Auto Traffic Avalanche

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes