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 workbench导入Joomla sample_data。sql文件到我的本地数据库。我希望它通过跳过导致错误的行继续导入,即使发生了错误。
Is there something I can prefix the SQL with to prevent the query from halting at any errors?
我是否可以在SQL前面加上前缀,以防止查询在出现任何错误时停止?
3 个解决方案
#1
77
try
试一试
mysql --force < sample_data.sql
Mysql help section says
Mysql帮助部分说
-f, --force Continue even if we get an sql error.
#2
29
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
#3
25
In MySQL Workbench, I unticked the option under Query to "Stop Script Execution on Errors":
在MySQL Workbench中,我去掉查询下的选项“错误停止脚本执行”:
It looks like Zimbabao's answer will work also.
看起来辛巴威的答案也同样有效。
In newer versions use 'Toggle whether execution of SQL script should continue after failed statements'
在较新的版本中,使用'切换SQL脚本在失败语句之后是否应该继续执行'
#1
77
try
试一试
mysql --force < sample_data.sql
Mysql help section says
Mysql帮助部分说
-f, --force Continue even if we get an sql error.
#2
29
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
#3
25
In MySQL Workbench, I unticked the option under Query to "Stop Script Execution on Errors":
在MySQL Workbench中,我去掉查询下的选项“错误停止脚本执行”:
It looks like Zimbabao's answer will work also.
看起来辛巴威的答案也同样有效。
In newer versions use 'Toggle whether execution of SQL script should continue after failed statements'
在较新的版本中,使用'切换SQL脚本在失败语句之后是否应该继续执行'