使用enable-local-infile时替换
我在 shell 脚本中有以下行:
/usr/bin/mysql --enable-local-infile --host=localhost --password=pass --user=db db < file.sql
目前,如果键匹配,它会添加新行。如果表中已存在产品部件,我希望替换它而不是添加新行。
我已在字段上添加了唯一索引,但我不确定如何在键与行匹配时替换上面的行。
I have the following line in a shell script:
/usr/bin/mysql --enable-local-infile --host=localhost --password=pass --user=db db < file.sql
At the moment it adds new lines if a key is matching. I want it to replace instead of adding new lines if a product part no already exists in a table.
I have added a unique index on the field but I'm not sure how to get the line above to replace if a key matches a row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经对此进行了排序:
我正在导入的 sql 文件的行格式如下:
加载数据本地 infile 'Products.txt' 替换为以 '|' 终止的表产品字段以 '\r\n' 结尾的行忽略 1 行;
这应该替换匹配的键/索引。由于我已将partno设置为唯一索引,如果我是正确的,这应该替换数据。
I think I've sorted this:
The sql file I'm importing has lines in the form:
load data local infile 'Products.txt' replace into table products fields terminated by '|' lines terminated by '\r\n' IGNORE 1 LINES;
this should replace on a matching key/index. As I've setup partno as a unique index this should replace data if I'm correct.