我正在使用MySQL工作台将Joomla sample_data.sql文件导入到我的本地数据库中.我希望它通过跳过导致错误的行来继续导入,即使发生错误也是如此.
有什么我可以在SQL前面加以防止查询在任何错误时停止吗?
Zim*_*bao 85
尝试
mysql --force < sample_data.sql
Run Code Online (Sandbox Code Playgroud)
Mysql帮助部分说
-f, --force Continue even if we get an sql error.
Run Code Online (Sandbox Code Playgroud)
Luk*_*ius 36
你也可以用 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
Run Code Online (Sandbox Code Playgroud)
Ste*_*eve 33
在MySQL Workbench中,我取消了查询下的选项"在错误上停止脚本执行":
看起来津巴布韦的答案也会起作用.
在较新的版本中,使用'切换是否应在失败的语句后继续执行SQL脚本'