Monday, April 15, 2013

MySQL: Prepared statement needs to be re-prepared

Problem:
While developing a web site on my development service provided by Dreamhost, I found that I would occasionally (and randomly) run into the following error:

General error: 1615 Prepared statement needs to be re-prepared

I began searching for a solution thinking it might be something with the Laravel framework. Then I found this page about a MySQL bug.

Solution:
Ultimately it appears that the best solution is to force the table cache to renew in mysql (more information about mysql repreperation), but if that is not an option, you can try forcing the table optimization or defragmentation for the table causing the issue.

This is understandably a work-around which is not idea for a production server. In the case of a production server, you can try modifying any of the following database settings:


table_open_cache 128=>16384
table_definition_cache 1024=>16384
tmp_table_size 32M=>64M
join_buffer_size 256k=>512k

If you have any more information on this issue, please post a comment below!

1 comment:

César said...

From my guru:

Too high values might crash the server, so before changing the cache try the following.

Open /etc/my.cnf and add

table_open_cache_instances = 2
Restart Mysql.. If you still get the error, than add

table_open_cache = 16384
table_definition_cache = 16384

and again restart Mysql

my actual values are 912 & 1024 and first solution is working.