SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded try restarting transaction

Today we ran into this error message using Magento: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction

We searched around a bit and found this solution that seems to work.

In lib/Zend/Db/Statement/Pdo.php find the public function _execute and replace the function with this code:

public function _execute(array $params = null)

{

// begin changes

$tries = 0;

do {

$retry = false;

try {

if ($params !== null) {

return $this->_stmt->execute($params);

} else {

return $this->_stmt->execute();

}

} catch (PDOException $e) {

#require_once ‘Zend/Db/Statement/Exception.php’;

if ($tries < 10 and $e->getMessage()==’SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction’) {

$retry = true;

} else {

throw new Zend_Db_Statement_Exception($e->getMessage());

}

$tries++;

}

} while ($retry);

// end changes

}

Then in lib/Varien/Db/Adapter/Mysqli.php find the raw_query with:

$tries = 0;

do {

$retry = false;

try {

$this->clear_result();

$result = $this->getConnection()->query($sql);

$this->clear_result();

}

catch (Exception $e) {

if ($tries < 10 and $e->getMessage()==’SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction’) {

$retry = true;

} else {

throw $e;

}

$tries++;

}

} while ($retry);

return $result;

}

Hopefully, that will take care of the error message “SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction” for you.