D
D
Dmitry Tarasov2020-06-22 13:23:46
MySQL
Dmitry Tarasov, 2020-06-22 13:23:46

How to fix deadlock in mysql?

Hello! The following error is thrown into the log.

Deadlock found when trying to get lock; try restarting transaction
            
UPDATE `tb_ads_dlink_visits` SET `status` =1, `money`=0.02771, `date`=1592807736 WHERE `idu` = 131986 and `ids` = 12735 and `status` = 0


I also run a cron every 5 minutes with this request.
DELETE FROM `tb_ads_dlink_visits` WHERE `status`='0' AND `date` < UNIX_TIMESTAMP() - 300


I understand they are somehow related, maybe not right.
Please tell me where to dig and why such an error occurs and how to solve such a problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2020-06-22
@fast-je

15.7.5 Deadlocks in InnoDB
remove delete from production. let unnecessary records accumulate better than rebuilding all indexes of the table will hang locks on parallel queries.
Just read the doc carefully under the link. practice shows that the easiest way to avoid locks is to correct the logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question