MySQL5中大資料錯誤:Packet for query is too large (****** > ******). You can change this value on the server by setting the max_allowed_packet' variable.;

來源:互聯網
上載者:User

標籤:pack   upd   targe   資料庫配置   ini   size   base   int   目的   

使用的MySQL資料庫版本:5.5

插入或更新欄位有大資料時(大於1M),會出現如下錯誤:

### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1132484 > 1048576). You can change this value on the server by setting the max_allowed_packet‘ variable.; SQL []; Packet for query is too large (1132484 > 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 (1132484 > 1048576). You can change this value on the server by setting the max_allowed_packet‘ variable.] with root causecom.mysql.jdbc.PacketTooBigException: Packet for query is too large (1132484 > 1048576). You can change this value on the server by setting the max_allowed_packet‘ variable.    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3910)    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2596)    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1307)    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)    at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)    at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:483)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)    at com.sun.proxy.$Proxy97.insert(Unknown Source)    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)    at com.sun.proxy.$Proxy98.insertClient(Unknown Source)    at com.shiliu.game.service.impl.ExcelUserServiceImpl.insertClient(ExcelUserServiceImpl.java:35)    at com.shiliu.game.controller.ClientController.batchimport(ClientController.java:171)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:483)    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:745)

報錯原因:

開始以為是相應欄位的類型設定不正確,超出了欄位的最大範圍,網上查詢後發現是mysql預設載入的資料檔案不超過1M,可以通過更改mysql的設定檔my.cnf(Linux,或windows的my.ini)來更改這一預設值,從而達到插入大資料的目的。

解決方案:

  1.SQL查詢下設定最大值

    SHOW VARIABLES LIKE ‘%max_allowed_packet%‘;

  2.找到MySQL安裝目錄修改my.ini設定檔

  3.尋找是否存在 max_allowed_packet 欄位,若有則修改其參數,沒有則添加。

 

  4.添加 max_allowed_packet 欄位

    [mysqld]

    max_allowed_packet = 20M

 

 5.重啟資料庫:

 

6.再查詢是否設定成功。

 

有時候命令“SET GLOBAL max_allowed_packet=16*1024*1024”無效

需要使用如下命令:set @@max_allowed_packet=5*1024*1024(這個我試了也無效..)

 

附加:三若

  若資料庫配置不能做修改

  若入你使用的是MyBatis,做添加或修改

  若你想知道java 中 list集合中有幾十萬條資料,每100條為一組取出來如何?

    請點擊我!

MySQL5中大資料錯誤:Packet for query is too large (****** > ******). You can change this value on the server by setting the max_allowed_packet' variable.;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.