如何使用断点进行mysql更新

时间:2022-03-08 23:10:22

I have 105000 records that I want to update
I want to change the value of a field called owner_id to a number that I want to set but each one number gets only 15000 record.

我有105000条记录要更新我想将名为owner_id的字段的值更改为我想要设置的数字,但每个数字只能获得15000条记录。

so each owner will have 15,000 records assigned to them. I can't user where id <1500 because they are not in order those records are in a table with 4 million records.

所以每个所有者将分配15,000条记录。我不能在id <1500的地方使用,因为它们不符合这些记录在400万条记录的表中的顺序。

Notice I want to do a mass change I am not worried about locking tables at this point

注意我想进行大规模更改我不担心此时锁定表格

This did not work

这没用

UPDATE phone_calls SET owner_id = 5 WHERE status = 1 LIMIT 15000, 30000

Thanks for the help

谢谢您的帮助

1 个解决方案

#1


1  

Your syntax is not correct. Use this query instead:

你的语法不正确。请改用此查询:

UPDATE phone_calls SET owner_id = 5 WHERE status = 1 AND owner_id <> 5 LIMIT 15000

It will update 15000 records only. The records already updated are excluded.
To update more records, run the query again (or put it in a loop).

它只会更新15000条记录。已更新的记录将被排除。要更新更多记录,请再次运行查询(或将其置于循环中)。

#1


1  

Your syntax is not correct. Use this query instead:

你的语法不正确。请改用此查询:

UPDATE phone_calls SET owner_id = 5 WHERE status = 1 AND owner_id <> 5 LIMIT 15000

It will update 15000 records only. The records already updated are excluded.
To update more records, run the query again (or put it in a loop).

它只会更新15000条记录。已更新的记录将被排除。要更新更多记录,请再次运行查询(或将其置于循环中)。