Mysql PacketTooBigException Packet for query is too large

一、問題描述

今天編輯富文本內容提交更新到數據庫時,遇到以下錯誤:

Error updating database.  Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (23663004 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.

編輯器用的是 vue-quill-editor,這個編輯器對圖片的處理是把圖片進行 Base64 編碼到文本中。

以上的錯誤提示裏,是說查詢的數據包太大??

二、解決方案

以上錯誤提示也給出了方案,設置 Mysql 的 max_allowed_packet 就可以了。
my.cnf(Linux) 或 my.init(Windows) 文件的 [mysqld] 下方,增加一行設置:

[mysqld]
max_allowed_packet=128M

這個值默認是 4M,最大可設置爲 1G,設置時必須是 1024 的倍數,否則會被 rounded down 到最近的一個 1024 的倍數值。

然後重啓 Mysql 即可:

# service mysql restart

Mysql 官方文檔 說明:

- - -
System Variable Name max_allowed_packet
System Variable Variable Scope Global, Session
System Variable Dynamic Variable Yes
- - -
Permitted Values Type integer
Permitted Values Default 4194304
Permitted Values Min Value 1024
Permitted Values Max Value 1073741824

The maximum size of one packet or any generated/intermediate string, or any parameter sent by the mysql_stmt_send_long_data() C API function. The default is 4MB.

The packet message buffer is initialized to net_buffer_length bytes, but can grow up to max_allowed_packet bytes when needed. This value by default is small, to catch large (possibly incorrect) packets.

You must increase this value if you are using large BLOB columns or long strings. It should be as big as the largest BLOB you want to use. The protocol limit for max_allowed_packet is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.

When you change the message buffer size by changing the value of the max_allowed_packet variable, you should also change the buffer size on the client side if your client program permits it. The default max_allowed_packet value built in to the client library is 1GB, but individual client programs might override this. For example, mysql and mysqldump have defaults of 16MB and 24MB, respectively. They also enable you to change the client-side value by setting max_allowed_packet on the command line or in an option file.

The session value of this variable is read only. The client can receive up to as many bytes as the session value. However, the server will not send to the client more bytes than the current global max_allowed_packet value. (The global value could be less than the session value if the global value is changed after the client connects.)

三、參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章