Continue SQL query even on errors in MySQL workbench

前端 未结 3 693
别那么骄傲
别那么骄傲 2020-12-03 04:04

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 th

相关标签:
3条回答
  • 2020-12-03 04:36

    try

    mysql --force < sample_data.sql 
    

    Mysql help section says

     -f, --force         Continue even if we get an sql error.
    
    0 讨论(0)
  • 2020-12-03 04:42

    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
    
    0 讨论(0)
  • 2020-12-03 04:51

    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

    0 讨论(0)
提交回复
热议问题