场景:
数据分了50个以上的表,分表数据查询使用视图查看
数据库异常代码:
java.sql.SQLException: Prepared statement needs to be re-prepared
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1160)
解决问题:
数据库输入 SET GLOBAL table_open_cache=16384;
SET GLOBAL table_definition_cache=16384;
另外输入之后,别忘点击提交
查看table_open_cache量
mysql的两个全局变量(打开表的缓存数量,表定义缓存数量)的设置值过小,而你的数据库表数量较多的情况。
1、打开表的缓存数量(table_open_cache)查询sql: SHOW VARIABLES LIKE '%table_open_cache%';
2、表定义缓存数量(table_definition_cache) 查询sql : SHOW VARIABLES LIKE '%table_definition_cache%';