com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024)

來源:互聯網
上載者:User

標籤:使用   htm   大小   service   查看   tar   技術   can   grep   

### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024). You can change this value on the server by setting the max_allowed_packet‘ variable.

; SQL []; Packet for query is too large (1169 > 1024). 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 (1169 > 1024). You can change this value on the server by setting the max_allowed_packet‘ variable.

 

我是進入到查看資料庫的:

show VARIABLES like ‘%max_allowed_packet%‘;

太小導致出錯。

在linux下,進入到mysql安裝目錄下:

進入到:

/usr/local/mysql,找到my.cnf,增加一行

max_allowed_packet = 20M

 

重啟mysql:

service mysql restart

 

然後在查詢:

 

 好了,以上解決!

 

 

 

 

 

 

 

在做查詢資料庫操作時,報了以上錯誤,還有out of memery heap hacp ,原因是MySQL的max_allowed_packet設定過小引起的,我一開始設定的是1M,後來改為了20M

 

mysql根據設定檔會限制server接受的資料包大小。

有時候大的插入和更新會被max_allowed_packet 參數限制掉,導致失敗。

查看目前配置
show VARIABLES like ‘%max_allowed_packet%‘;

顯示的結果為:

+--------------------+---------+ | Variable_name      | Value   | +--------------------+---------+ | max_allowed_packet | 1048576 | +--------------------+---------+  

以上說明目前的配置是:1M

 
修改方法
1) 方法1
可以編輯my.cnf來修改(windows下my.ini),在[mysqld]段或者mysql的server配置段進行修改。
max_allowed_packet = 20M
如果找不到my.cnf可以通過

mysql --help | grep my.cnf

去尋找my.cnf檔案。
2) 方法2

(很妥協,很糾結的辦法)
進入mysql server
在mysql 命令列中運行
set global max_allowed_packet = 2*1024*1024*10
然後關閉掉這此mysql server連結,再進入。
show VARIABLES like ‘%max_allowed_packet%‘;
查看下max_allowed_packet是否編輯成功
 

經驗總結:
在很多台機器上用方法一都沒問題,但2011年11月14日遇到一台機器死活都不成功,
使用命令列方式:set global max_allowed_packet = 16M;
也不行,但使用
set global max_allowed_packet = 2*1024*1024*10;
成功了,很是鬱悶
問題終於找出來了,不是方法的問題,是設定完成後要把命令列退出重新登入查看,看來系統變數的值在登入後會緩衝。但在這台機器上使用配置INI檔案。

參考文檔:
http://www.360doc.com/content/11/0214/17/4171006_93014351.shtml
http://hi.baidu.com/jgs2009/blog/item/2de0701601186202c93d6dfd.html
http://www.cnblogs.com/phpfans2012/archive/2012/3/2.html
http://blog.csdn.net/wpekin/article/details/5661625
http://www.360doc.com/content/11/0214/17/4171006_93014351.shtml

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.