4

MySQL 8.0 has a new feature to allow a transaction to timeout immediately by throwing an error if it tried to access records that are locked by another transaction instead of waiting for that transaction to commit, or waiting for the time-out.

Is there a way to achieve the same effect in MySQL 5.7?

2 Answers 2

1

Server-side SELECT statement timeouts allows:

SET SESSION MAX_EXECUTION_TIME=2000;

Not exactly the same, but close.

1

MAX_EXECUTION_TIME can work for SELECT statements. I needed this to work with an INSERT statement:

SET SESSION INNODB_LOCK_WAIT_TIMEOUT = 2;

To make it work for a single INSERT statement, I did this:

SET @saved_lock_wait = @@SESSION.INNODB_LOCK_WAIT_TIMEOUT;
SET SESSION INNODB_LOCK_WAIT_TIMEOUT = 2;
-- The query...
SET SESSION INNODB_LOCK_WAIT_TIMEOUT = @saved_lock_wait;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.