<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="packet-too-large">
      </a>
      B.3.2.8 Packet Too Large
     </h4>
    </div>
   </div>
  </div>
  <p>
   A communication packet is a single SQL statement sent to the
          MySQL server, a single row that is sent to the client, or a
          binary log event sent from a replication source server to a
          replica.
  </p>
  <p>
   The largest possible packet that can be transmitted to or from
          a MySQL 8.4 server or client is 1GB.
  </p>
  <p>
   When a MySQL client or the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   server
          receives a packet bigger than
   <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
    <code class="literal">
     max_allowed_packet
    </code>
   </a>
   bytes, it
          issues an
   <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_net_packet_too_large" target="_top">
    <code class="literal">
     ER_NET_PACKET_TOO_LARGE
    </code>
   </a>
   error
          and closes the connection. With some clients, you may also get
          a
   <code class="literal">
    Lost connection to MySQL server during
          query
   </code>
   error if the communication packet is too
          large.
  </p>
  <p>
   Both the client and the server have their own
   <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
    <code class="literal">
     max_allowed_packet
    </code>
   </a>
   variable,
          so if you want to handle big packets, you must increase this
          variable both in the client and in the server.
  </p>
  <p>
   If you are using the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client program,
          its default
   <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
    <code class="literal">
     max_allowed_packet
    </code>
   </a>
   variable
          is 16MB. To set a larger value, start
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa96119891"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token constant">--max_allowed_packet</span><span class="token attr-value"><span class="token punctuation">=</span>32M</span></code></pre>
  </div>
  <p>
   That sets the packet size to 32MB.
  </p>
  <p>
   The server's default
   <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
    <code class="literal">
     max_allowed_packet
    </code>
   </a>
   value is
          64MB. You can increase this if the server needs to handle big
          queries (for example, if you are working with big
   <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
    <code class="literal">
     BLOB
    </code>
   </a>
   columns). For example, to
          set the variable to 128MB, start the server like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa65994170"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysqld</span> <span class="token constant">--max_allowed_packet</span><span class="token attr-value"><span class="token punctuation">=</span>128M</span></code></pre>
  </div>
  <p>
   You can also use an option file to set
   <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
    <code class="literal">
     max_allowed_packet
    </code>
   </a>
   . For
          example, to set the size for the server to 128MB, add the
          following lines in an option file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa53726827"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">max_allowed_packet</span><span class="token attr-value"><span class="token punctuation">=</span>128M</span></code></pre>
  </div>
  <p>
   It is safe to increase the value of this variable because the
          extra memory is allocated only when needed. For example,
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   allocates more memory only when you
          issue a long query or when
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   must
          return a large result row. The small default value of the
          variable is a precaution to catch incorrect packets between
          the client and server and also to ensure that you do not run
          out of memory by using large packets accidentally.
  </p>
  <p>
   You can also get strange problems with large packets if you
          are using large
   <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
    <code class="literal">
     BLOB
    </code>
   </a>
   values but
          have not given
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   access to enough
          memory to handle the query. If you suspect this is the case,
          try adding
   <span class="command">
    <strong>
     ulimit -d 256000
    </strong>
   </span>
   to the
          beginning of the
   <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysqld_safe
     </strong>
    </span>
   </a>
   script and
          restarting
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   .
  </p>
 </div>
 <br/>
</div>
