mysql insert race condition

后端 未结 8 1472
暗喜
暗喜 2020-12-09 06:19

How do you stop race conditions in MySQL? the problem at hand is caused by a simple algorithm:

  1. select a row from table
  2. if it doesn\'t exist, insert it
8条回答
  •  醉话见心
    2020-12-09 06:37

    what you want is LOCK TABLES

    or if that seems excessive how about INSERT IGNORE with a check that the row was actually inserted.

    If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead.

提交回复
热议问题