mysql多線程寫入出現臟數據(重復數據)問題?
mysql 多線程寫入,會出現臟數據.mysql多線程寫入出現臟數據(重復數據)問題?
- 第一方法:
在要插入的表中增加唯一索引,就會防止插入多條相同的數據 - 第二方法:
使用 insert .... where not exists .... 語句 - 例如:
insert into cash_out(user_id, state) select * from ( select 173153, 0 ) AS tmp where not exists ( select * from cash_out where user_id=173153 and state=0) limit 1;