报错:org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO SYS_UPLOAD_FILE(juid,filename,fileio,intime) VALUES(?,?,?,sysdate())]; Packet for query is too large (19469578 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.; nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (19469578 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
主要是mysql的JDBC连接限制了最大包长度1024B,即1KB。
果断去数据库里面查询当前数据库的包长度显示:show VARIABLES like '%max_allowed_packet%';
可使用两种方法修改此参数
1、连接数据库服务器,登录 mysql, 执行命令:set global max_allowed_packet = 2*1024*10并执行。退出后,重新登录 mysql ,再次查看这个系统项的值, 注意,必须重新登录mysql,否则这个值还是显示为原始值(缓存)!。
注意:此种方式,每次电脑重启都会讲数据库缓存初始化,也就是需要重新设置max_allowed_packet值。
2、还有种方法可使用。修改mysql.cnf(windows下my.ini),在[mysqld]段或者mysql的server配置段进行修改。
max_allowed_packet = 20K
此方法需要重启mysql才行。
配置部分截取:
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
max_allowed_packet = 20M
# The TCP/IP Port the MySQL Server will listen on
port=3306