how to avoid deadlock in mysql
Posted
by noam
on Stack Overflow
See other posts from Stack Overflow
or by noam
Published on 2010-03-18T13:41:59Z
Indexed on
2010/03/18
14:31 UTC
Read the original article
Hit count: 211
I have the following query (all tables are innoDB)
INSERT INTO busy_machines(machine)
SELECT machine FROM all_machines
WHERE machine NOT IN (SELECT machine FROM busy_machines)
and machine_name!='Main'
LIMIT 1
Which causes a deadlock when I run it in threads, obviously because of the inner select, right?
The error I get is:
(1213, 'Deadlock found when trying to get lock; try restarting transaction')
How can I avoid the deadlock? Is there a way to change to query to make it work, or do I need to do something else?
© Stack Overflow or respective owner