使用enable-local-infile时替换

发布于 2024-10-24 22:25:18 字数 225 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2024-10-31 22:25:18

我想我已经对此进行了排序:

我正在导入的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文