This is a lock conflict problem, which ultimately leads to a timeout on one of the locks. Here are some suggestions:
- Make sure you have the correct indexes, as a result of which row-level locks are blocked, not table-level locks . This will reduce competition.
- Make sure you have indexes in foreign keys . To check relational constraints during
insert or update , some database locks the entire referenced table if there is no such index (I don't know if this applies to MySQL) - If the problem is still there, try to make the transaction faster / smaller. Again, this will reduce competition in the database.
- Increase the wait time, but keep a reasonable value
source share