Continue SQL query even on errors in MySQL workbench

MysqlHalt

Mysql Problem Overview


I'm using MySQL workbench to import a Joomla sample_data.sql file into my local database. I want it to continue importing, even if an error occurs, by skipping the line that caused the error.

Is there something I can prefix the SQL with to prevent the query from halting at any errors?

Mysql Solutions


Solution 1 - Mysql

try

mysql --force < sample_data.sql 

Mysql help section says

 -f, --force         Continue even if we get an sql error.

Solution 2 - Mysql

You could also use INSERT IGNORE

INSERT IGNORE INTO mytable
 (primaryKey, field1, field2)
VALUES
 ('1', 1, 2),
 ('1', 3, 4), //will not be inserted
 ('2', 5, 6); //will be inserted

Solution 3 - Mysql

In MySQL Workbench, I unticked the option under Query to "Stop Script Execution on Errors":

enter image description here

It looks like Zimbabao's answer will work also.


In newer versions use 'Toggle whether execution of SQL script should continue after failed statements'

Toggle whether execution of SQL script should continue after failed statements

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSteveView Question on Stackoverflow
Solution 1 - MysqlZimbabaoView Answer on Stackoverflow
Solution 2 - MysqlLukas IgnatavičiusView Answer on Stackoverflow
Solution 3 - MysqlSteveView Answer on Stackoverflow