MySQL operation failed: Unknown prepared statement handler (${#}) given to mysqld_stmt_execute
See original GitHub issueI have a service that has been running in production for a month with no issues. Last evening, the service failed after all queries using .execute
were throwing this error. Restarting the service resolved the issue.
Let me know if I can provide more information.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
MySQL connection throws "Unknown prepared statement ...
If prepare failed, that is where you would check the error messages and exit the function. I would suggest only proceeding if the...
Read more >Unknown prepared statement handler (stmt) given to EXECUTE
An error "Unknown prepared statement handler (stmt) given to EXECUTE" means that previous PREPARE statement fails.
Read more >Unknown prepared statement handler (X) given to ...
I have a java application calling percona mysql through a generic data access library. Every so often calls will fail with this error:-...
Read more >43096: Unknown prepared statement handler (1) given to ...
Description: java.sql.SQLException: Unknown prepared statement handler (1) given to mysql_stmt_execute at com.mysql.jdbc.SQLError.
Read more >php - Unknown prepared statement handler given to ...
Unknown prepared statement handler (4) given to mysqld_stmt_execute ... die('bind_param() failed: ' . htmlspecialchars($stmt->error)); } ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually it does appear that manual
prepare()
statements are both cached and retrieved from theconnection._statements
LRU cache. Which is the source of the bug.In the case of a manual
.prepare()
thenPreparedStatementInfo.close()
aCloseStatement
is sent but the statement entry is not removed from the cache. Leaving an entry to the invalid prepared statement.Replication:
prepare()
an insert query,execute()
andclose()
it. Attempting toprepare()
andexecute()
the same SQL a second time triggers this issue.Solution:
prepare()
statementsPreparedStatementInfo.close()
correctly delete the statement from theconnection._statements
cacheTL;DR for anyone facing the same issue: rallfo found the exact cause of this, simply use
Connection.unprepare()
when you’ve done with your instead ofPreparedStatementInfo.close()
solves the problem. I’ve opened https://github.com/sidorares/node-mysql2/pull/1493 to address this, hopefully it clarifies the usage.