即使在 MySQL 工作台中出现错误,也继续 SQL 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5366436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:12:23  来源:igfitidea点击:

Continue SQL query even on errors in MySQL workbench

mysqlhalt

提问by Steve

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.

我正在使用 MySQL 工作台将 Joomla sample_data.sql 文件导入我的本地数据库。我希望它通过跳过导致错误的行来继续导入,即使发生错误。

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

有什么我可以在 SQL 前面加上前缀来防止查询在出现任何错误时停止的吗?

采纳答案by Steve

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

在 MySQL Workbench 中,我取消了 Query 下的选项以“Stop Script Execution on Errors”:

enter image description here

在此处输入图片说明

It looks like Zimbabao's answer will work also.

看起来 Zimbabao 的答案也将起作用。



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

在较新的版本中,使用“在语句失败后切换是否应继续执行 SQL 脚本”

Toggle whether execution of SQL script should continue after failed statements

切换是否在语句失败后继续执行 SQL 脚本

回答by Zimbabao

try

尝试

mysql --force < sample_data.sql 

Mysql help section says

Mysql帮助部分说

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

回答by Lukas Ignatavi?ius

You could also use INSERT IGNORE

你也可以使用 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