zoukankan      html  css  js  c++  java
  • mysql中,由于JDBC连接限制了最大包长度1024B,即1KB,报错“max_allowed_packet' ”

      报错: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(windowsmy.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

     

  • 相关阅读:
    .net core2.0 中使用aspectcore实现aop
    [Superset] 设置Superset的登录设置
    [Python]Pandas对于非唯一的label index的数据选择问题
    Data Science Radar测试结果
    [R]R包版本更迭【持续更新】
    [面试] 删除多余的数组内容
    [Python]Python中的包(Package)
    [Linux] 使用Yum在CentOS上安装MySQL
    [pyMongo]insert_many的Bulkwrite实现机制
    [Git]2018-10 解决git cmd中文乱码问题
  • 原文地址:https://www.cnblogs.com/lojun/p/7128197.html
Copyright © 2011-2022 走看看