What does the MySQL "max_allowed_packet" setting actually control?

8

2

We've been cleaning up database problems for the last four hours, thanks to a broken mysqldump that wasn't sufficiently erroring out. We were getting these errors:

mysqldump: Error 2020: Got packet bigger than "max_allowed_packet" bytes when dumping table "search_dataset" at row: 68014

What the heck does that setting do? It's obviously not IP packet size, since I have it set to 32M now. Why does it exist?

Plutor

Posted 2011-04-21T15:39:56.877

Reputation: 541

Answers

7

According to the page 99 of "Understanding MySQL Internals" (ISBN 0-596-00957-7), here are paragraphs 1-3 explaining it:

MySQL network communication code was written under the assumption that queries are always reasonably short, and therefore can be sent to and processed by the server in one chunk, which is called a packet in MySQL terminology. The server allocates the memory for a temporary buffer to store the packet, and it requests enough to fit it entirely. This architecture requires a precaution to avoid having the server run out of memory---a cap on the size of the packet, which this option accomplishes.

The code of interest in relation to this option is found in sql/net_serv.cc. Take a look at my_net_read(), then follow the call to my_real_read() and pay particular attention to net_realloc().

This variable also limits the length of a result of many string functons. See sql/field.cc and sql/intem_strfunc.cc for details.

This is probably the most complete explanation of max_allowed_packet I have ever seen. I typed those 3 paragraphs right from the book.

RolandoMySQLDBA

Posted 2011-04-21T15:39:56.877

Reputation: 2 675

Thanks for posting that. It seems to hint that "packet" means "IP packet." – Randolf Richardson – 2011-04-21T20:43:08.740

Great answer. I guess this is as close as I'm getting to a real answer. (I'm still pretty sure this isn't referring to IP packets. It doesn't mention IP anywhere, and I believe 65535 bytes is typically the real-world limit for even fragmented IP packets.) – Plutor – 2011-04-22T13:47:26.940

1

The documentation explains it in full detail here:

"The maximum size of one packet or any generated/intermediate string. ..."

The documentation also goes on to address BLOBs and how this setting ties into them.

Randolf Richardson

Posted 2011-04-21T15:39:56.877

Reputation: 14 002

That doesn't really answer my question. What's a packet in this context? Is it actually an IP packet? Isn't there a better way than a simple byte limit to catch malformed data? – Plutor – 2011-04-21T16:35:55.643

Unless they define "packet" as being something else (which they don't appear to do in the documentation), it is reasonable to expect that "packet" refers to an IP packet. – Randolf Richardson – 2011-04-21T18:20:17.757

I found the definition in a book I have. I added an excerpt from that book as my answer. – RolandoMySQLDBA – 2011-04-21T20:07:56.397