开发者

MYSQL Bulk "INSERT ... ON DUPLICATE KEY UPDATE ..." via "LOAD DATA INFILE"

开发者 https://www.devze.com 2023-03-21 04:04 出处:网络
Hej, I need to mass-update a t开发者_运维知识库able. Am I allowed to use mysql\'s \"LOAD DATA INFILE\" Statement together with \"INSERT … ON DUPLICATE KEY UPDATE\" statements to fulfill my task?Depe

Hej,

I need to mass-update a t开发者_运维知识库able. Am I allowed to use mysql's "LOAD DATA INFILE" Statement together with "INSERT … ON DUPLICATE KEY UPDATE" statements to fulfill my task?


Depending on your exact requirements, you may be able to accomplish this using the REPLACE option of LOAD DATA INFILE. From the manual:

  • If you specify REPLACE, input rows replace existing rows. In other words, rows that have the same value for a primary key or unique index as an existing row. See Section 12.2.7, “REPLACE Syntax”.

Example:

LOAD DATA INFILE '/tmp/data.txt'
REPLACE INTO TABLE your_table
(column1, column2, ...)
0

精彩评论

暂无评论...
验证码 换一张
取 消