I get a Deadlock found when trying to get lock; try restarting transaction error Deadlock found when trying to get lock; try restarting transaction Deadlock found when trying to get lock; try restarting transaction on my InnoDB tables. Here is the request:
UPDATE views SET visit_cnt = visit_cnt + 1 WHERE visit_day = DATE(NOW()) AND article_id = '4838'
This query also launches this using the ON UPDATE button:
UPDATE articles SET views = views + 1 WHERE id = NEW.article.id
Here's how I tried to fix it:
$attempts_left = 5; do { mysql_query ($query); // if we found a deadlock, we will try this query 4 more times if (mysql_errno () == 1213) { // 1213 - deadlock error $deadlocked = true; $attempts_left --; } else{ $deadlocked = false; } } while($deadlocked && $attempts_left > 0);
My question is: is this the only way to deal with a dead end? I mean, this is pretty ugly, and in any case does happen from time to time. Is there a recommended way to eliminate deadlocks?
Silver light
source share