每隔一段时间我就会收到一个mysql错误。错误是
Deadlock found when trying to get lock; try restarting transaction
查询为
var res = cn.Execute("insert ignore into
Post(desc, item_id, user, flags)
select @desc, @itemid, @userid, 0",
new { desc, itemid, userid });
这个问题究竟是如何导致它的呢?在谷歌搜索时,我看到了一些关于查询如何占用很长的锁行
我有一个带有自定义httpModule的WCF Webservice,我使用它对MysqlMembership进行用户名/密码身份验证。
public void Init(HttpApplication application)
{
application.AuthenticateRequest += new EventHandler(this.OnAuthenticateRequest);
application.EndRequest += new EventHandler(this.OnEndRequest);
}
public v
在我的客户端应用程序中,我有一个类似这样的方法(实际上它更复杂,但我留下了主要部分):
public void btnUpdate_Click(...)
{
...
dataAdapter.Update(...);
...
dataAdapter.Fill(...); // here I got exception one time
}
我在日志中发现的异常是“尝试获取锁时发现死锁;尝试重新启动事务”。我只遇到过一次这个异常,所以它没有重复。
据我所知,DataAdapter.Fill()方法只执行select查询。我不进行显式事务,并且启用了自动提交。
那么,我如何才能在一个
我有一些带有死锁的MySQL (innodb),我只是想杀死这些事务,然后继续前进。
“显示引擎INNODB状态”显示如下:
*** (1) TRANSACTION:
TRANSACTION 74D88AFE, ACTIVE 14 sec starting index read
mysql tables in use 3, locked 3
LOCK WAIT 3 lock struct(s), heap size 1248, 2 row lock(s)
MySQL thread id 4637121, OS thread handle 0x7f51f91be700, query id 979
我不明白两个重复查询,每个查询使用主键删除单个表上的一行,怎么会死锁。有谁能解释一下吗?
在我看来,其中一个事务应该获得锁,而另一个事务则必须等待。
以下是死锁报告,以及查询:
Fri Jun 01 2012 13:50:23
*** (1) TRANSACTION:
TRANSACTION 3 1439005348, ACTIVE 0 sec, process no 22419, OS thread id 1166235968 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), hea
在查询包含UPDATE和JOIN的语句时,我们将得到以下错误:
Statements writing to a table with an auto-increment column after selecting
from another table are unsafe because the order in which rows are
retrieved determines what (if any) rows will be written.
This order cannot be predicted and may differ on master and the slave
在高并发性下,当在一夜之间运行一个每日进程时,我们会看到某个特定表上出现死锁,这似乎是指它当时持有一个间隙锁。然而,我无法以一种理智的方式再现这一切。
在为更新而锁定的事务期间运行的代码的简化版本(因为对特定“帐户”插入到此表的准确性很重要)如下:
select created_at, new_balance from (select created_at, id,
new_balance from bad_table where account_type = 'subscription' and
account_id = '123456' and curr
我遇到的情况是,两个事务会造成mysql死锁。
引发以下错误:Deadlock found when trying to get lock; try restarting transaction
如果我是正确的,这个错误意味着mysql死锁超时已经过期,mysql试图做些什么来消除这个死锁。
对我来说不清楚的是,try restarting transaction是什么意思?如何“重新启动”事务?
两个锁定的事务会发生什么?他们都被取消了吗(滚回)?或者只是其中一个被取消了锁才能被释放。
提前感谢
我检查了其他类似的问题,例如堆栈溢出中的“死锁在MySQL中”,但是没有任何问题导致解决方案。
REPLACE INTO db2.table2 (id, some_identifier_id, name, created_at, updated_at) (SELECT id, some_identifier_id, name, created_at, updated_at FROM db1.table1 WHERE some_identifier_id IS NOT NULL AND some_identifier_id NOT IN (SELECT some_identifier_id FR
我在我的InnoDB表上得到了一个Deadlock found when trying to get lock; try restarting transaction错误。下面是查询:
UPDATE views
SET visit_cnt = visit_cnt + 1
WHERE visit_day = DATE(NOW())
AND article_id = '4838'
此查询还通过ON UPDATE trigger触发:
UPDATE articles
SET views = views + 1
WHERE id = NEW.article.id
以下是我尝试
我有一个mysql DELETE查询,其中where子句使用带有IN的主键:
delete from my_table where id in (4, 900, 700);
我收到了死锁错误。我不明白为什么会这样,也不知道如何避免。虽然其他查询正在从同一个表中选择/删除/添加,但没有为这些ID选择任何其他查询。PK id是特定于单个用户的,因此没有其他人使用这些相同的id。我认为使用主键可以防止delete语句锁定其他行。
编辑:引擎为innoDB
我有一个应用程序与数据库有一些问题:当它试图打开到数据库的连接时突然冻结(或者执行查询,这是不清楚的)。没有错误消息。我怀疑有一些查询阻塞了其他人,我正在试图弄清楚这是什么。我用过
SET profiling=1;
但当我执行:
show profiles;
我只得到我自己执行的查询,而不是应用程序查询(应用程序和我使用的是同一个用户)。
呼叫
SHOW FULL PROCESSLIST;
返回一个具有所有进程的表。
+-----+----------+---------------------+--------+---------+------+-------+--------------
有时,对于只是一个选择查询的存储过程,我会遇到以下错误:Transaction (Process ID 91) was deadlocked on lock
我最初的理解是,select查询不会锁定一个表,或者即使它试图查询的表正在被另一个进程更新/锁定,也不会导致死锁,但看起来select查询也可能导致死锁。
如果我将查询的隔离级别设置为read uncommitted,会解决问题吗?
最近,由于以下事务并行运行,我遇到了MySQL死锁:
(given `ei_id` and `dst_site`)
SELECT id from item_specifics WHERE ei_id=X AND dst_site=Y;
(run only if any ids from above select)
DELETE FROM item_specifics WHERE id in (2,3,1);
(next multiple inserts are executed) e.g.
INSERT INTO item_specifics (category_id,
我面临以下例外:
com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
我可以告诉您的是,我有多个线程并行地在相同的表上执行查询。但我不明白为什么会出现这种异常。因为如果一个查询锁定了一个表,那么另一个线程中的同一个查询(或同一表上的其他查询)将等待锁。为什么会造成死锁?
我用不同的话重复,我理解异常,但我不明白的是,一个查询正在等待其他查询,另一个查询应该执行,离开锁,等待查询可以