mysql source 忽略错误继续执行

本文探讨了在使用MySQL命令行工具进行批量数据导入时遇到的问题,并提供了如何避免因单条语句错误而导致整个导入过程失败的有效解决方案。

mysql -h$1 -P$2 -u$3 -p$4 -D$5 -s -N -e  " source$TAB_ONLY_LIST"

发现一个语句报错,整个过程就失败了。


增加--force 或-f依旧报错

mysql -h$1 -P$2 -u$3 -p$4 -D$5 -s -N -f -e  " source$TAB_ONLY_LIST"


网上查了一下,说这不是bug,解决方案是

mysql -h$1 -P$2 -u$3 -p$4 -D$5 -s -N -f <"$TAB_ONLY_LIST"


https://bugs.mysql.com/bug.php?id=533

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

--force is intended to be used in Batch Mode only. I.e. like:

mysql --force < myscript.sql

# Unix style
cat myscript.sql | mysql --force

# Windows style
type myscript.sql | mysql --force

-e "" is intened to send Single query or command that's why --force does not make much sence for it. Single query can either succeed or fail. Maning of --force is to continue executing batch of queries even if some of them fail. Without it mysql will stop after first error.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值