سؤال

I need to execute a SQL dump with very large extended inserts. I'm using the official command-line tool in my computer to connect to a server in the LAN. The execution always dies:

ERROR 2006 (HY000): MySQL server has gone away

... and I'm fairly sure that it's due to a tiny max_allowed_packet setting:

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+----------+
| Variable_name      | Value    |
+--------------------+----------+
| max_allowed_packet | 10485760 |
+--------------------+----------+

There're lots of documentation on how to change the setting in the server but I wonder if it's possible to change it just for current connection, i.e., from the client side. I don't need a general solution, I'll be happy if it works for the command line tool.

I've checked documentation and found this:

max_allowed_packet

The maximum packet length to send to or receive from the server. (Default value is 16MB.)

... and subsequently tried this:

mysql ^
    --max_allowed_packet=50M ^
    --compress ^
    --default-character-set=utf8 ^
    --skip-reconnect ^
    -h mysql.example.com -u foo -b bar

Result: all commands to read max_allowed_packet still report 10MB and server still goes away.

Can you increase max_allowed_packet from the client side?

هل كانت مفيدة؟

المحلول

I've read many articles that explain how to accomplish this but I've reached the conclusion that they simply haven't tested it properly. My conclusions are:

  • Server's max_allowed_packet is a hard-coded upper limit. You can change it for the whole server as any other server-side setting (configuration file or server command-line parameters) but it isn't possible to increase it from the client.

  • Some clients (such as the official command line utility) allow to set max_allowed_packet on connection. It's the only way to actually change the value from a client (changing session or global variables has no effect on the size of exchanged packages) but it's only useful if you want to lower it. Sending packages larger than the server's setting will still trigger package related errors since the server will not accept them.

To sum up:

  1. You have to treat max_allowed_packet as read-only.
  2. If it's too small, you need to change it for the whole server or live with it.

It's a pity that I cannot provide links to official documentation but this subject is poorly documented.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top