我有一个数据库,我正在尝试更新行值,但我得到一个"锁定等待超时"错误。这就是表格的样子:
mysql> use rti;
Database changed
mysql> explain resin_products;
+--------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+-------+
| resin_product_id | int(11) | NO | PRI | NULL | |
| manufacturer | varchar(45) | YES | | NULL | |
| name | varchar(45) | YES | | NULL | |
| model_number | varchar(45) | YES | | NULL | |
| resin_type | varchar(45) | YES | | NULL | |
| primary_type | varchar(45) | YES | | NULL | |
| group | varchar(45) | YES | | NULL | |
| teir | varchar(45) | YES | | NULL | |
| chemical_structure | varchar(45) | YES | | NULL | |
| physical_structure | varchar(45) | YES | | NULL | |
| color | varchar(45) | YES | | NULL | |
| total_capacity | varchar(45) | YES | | NULL | |
| salt_split_CAP | varchar(45) | YES | | NULL | |
| price_per_cuft | varchar(45) | YES | | NULL | |
| comments | varchar(500) | YES | | NULL | |
+--------------------+--------------+------+-----+---------+-------+
这是命令:
mysql> UPDATE resin_products SET price_per_cuft='00.04' WHERE resin_product_id=1;
这是大约30秒后发生的错误:
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
这就是我的" lock_wait"变量设置为:
mysql> show variables like 'lock_wait_timeout';
+-------------------+----------+
| Variable_name | Value |
+-------------------+----------+
| lock_wait_timeout | 31536000 |
+-------------------+----------+
1 row in set (0.00 sec)
答案 0 :(得分:1)
首先查看锁定表的列表:
public static List<ErrorLogData> GetLogErrorData(string appName, InputData data)
{
SqlConnection con;
List<ErrorLogData> errorLogData = null;
string query = "";
if (data.DateFrom == "" && data.DateTo == "")
{
query += "from ld in logData.errorLogs.Take(10000)";
}
if (data.DateFrom == "" && data.DateTo != "")
{
query += "from ld in logData.errorLogs where ld.errorTime <= " + data.DateTo;
}
if (data.DateFrom != "" && data.DateTo == "")
{
query += "from ld in logData.errorLogs where ld.errorTime >= " + data.DateFrom + " && <= " + DateTime.Now;
}
if (data.DateFrom != "" && data.DateTo != "")
{
query += "from ld in logData.errorLogs where ld.errorTime >= " + data.DateFrom + " && <= " + data.DateTo;
}
DateTime dateFrom = Convert.ToDateTime(data.DateFrom);
DateTime dateTo = Convert.ToDateTime(data.DateTo);
using (con = new SqlConnection(ConfigurationManager.AppSettings[conKey]))
using (WebEntities logData = new WebEntities())
{
logData.CommandTimeout = 300;
var errorLog = query +
select new ErrorLogData
{
ErrorID = ld.errorID,
ErrorTime = ld.errorTime,
UserName = ld.username,
ErrorType = ld.errorType,
Error = ld.error,
ControlNumber = ld.controlNumber
};
errorLogData = errorLog.ToList();
}
return errorLogData;
}
你也可以看到使用这个表的线程:
query
然后你可以杀死那个线程
select new ErrorLogData...