如何在导入错误的 MySQL 转储时跳过行
鉴于错误的 mysqldump 会导致导入错误:
namtar backups # mysql -p < 2010-12-01.sql
Enter password:
ERROR 1062 (23000) at line 8020: Duplicate entry 'l�he?' for key 'wrd_txt'
是否有一种简单的方法可以告诉导入跳过给定行并继续?
(是的,我知道我可以手动编辑文件或解析输出,但这不是很方便)
Given bad mysqldump
that causes error on import:
namtar backups # mysql -p < 2010-12-01.sql
Enter password:
ERROR 1062 (23000) at line 8020: Duplicate entry 'l�he?' for key 'wrd_txt'
Is there an easy way to tell import to just skip given row and continue?
(Yes, I know I can manually edit the file or parse output, but it's not very convinient)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您可以再次进行转储,则可以在转储时将
--insert-ignore
添加到命令行。或者你可以尝试使用mysqlimport命令和
--force
,即使遇到MySQL错误也会继续。If you can make the dump again you could add
--insert-ignore
to the command-line when dumping.Or you can try using the mysqlimport command with
--force
,which will continue even if it encounters MySQL Errors.mysql -f -p
mysql -f -p
mysql -f -p
2010-12-01.sql
-f
(强制)是这里的操作选项,对我有用。mysql -f -p < 2010-12-01.sql
the
-f
(force) being the operative option here, worked for me.根据 jmlsteele 的回答和评论的建议,以下是如何将插入动态转换为
INSERT IGNORE
。如果您从
sql
文件导入:如果您从
gz
文件导入,只需将gunzip 的输出通过管道传输到 sed,而不是使用文件输入:Following the advice from jmlsteele's answer and comment, here's how to turn the inserts into
INSERT IGNORE
on the fly.If you're importing from an
sql
file:If you're importing from a
gz
file, just pipe the output from gunzip into sed instead of using the file input:其他选项当然也是可行的选项,但另一个解决方案是简单地编辑从 mysqldump 获取的 .sql 文件。
更改:
至
The other options certainly are viable options, but another solution would be to simply edit the
.sql
file obtained from themysqldump
.Change:
TO
很棒的提示。我做了一点不同但结果相同。
Great tip. I did it a little different but same result.
想一想你是否删除了转储顶部的 MySQL 指令?
(当我删除已使用 sed 命令插入的所有记录/表后重新启动恢复时,我无意中这样做了)。这些指令告诉 MySQL,除其他外,不要进行唯一测试、外键测试等)
Just a thought did you delete the MySQL directives at the top of dump?
(I unintentionally did when I restarted a restore after deleting all the records/tables I'd already inserted with a sed command). These directives tell MySQL ,among other things, not to do unique tests, foreign key tests etc)