An import fails with “Server has gone away”
An import loses its connection when a row exceeds MariaDB's default max_allowed_packet limit of 16 MB. The log reports the oversized packet, and raising the limit on both the server and the client fixes the import.
Symptoms
The import stops with this error.
ERROR 2006 (HY000) at line 2: Server has gone awayAt the same time, MariaDB logs the following warning. Check /var/log/mariadb/mariadb.log on AlmaLinux or run journalctl -u mariadb on Ubuntu.
[Warning] Aborted connection 38 to db: 'example_db' user: 'example_db' host: 'localhost' (Got a packet bigger than 'max_allowed_packet' bytes)Cause
A row in the dump, often one with a large blob or a long text value, exceeds max_allowed_packet. The server defaults to 16 MB, or 16777216 bytes. UrbeStack leaves the value to the distribution and to you.
The server and the mariadb client each have their own limit. Both must accept the packet.
Resolution
Check the server's current limit.
mariadb -N -e "SELECT @@global.max_allowed_packet"Raise the server's limit to 64 MB immediately. This setting lasts until MariaDB restarts.
mariadb -e "SET GLOBAL max_allowed_packet=67108864"To keep the setting after a restart, add
max_allowed_packet = 64Munder[mysqld]in/etc/my.cnf.d/mariadb-server.cnfon AlmaLinux or/etc/mysql/mariadb.conf.d/50-server.cnfon Ubuntu. Then restart MariaDB.urbestack-service-restart --name mariadbImport the dump with the client's limit set to 64 MB as well.
mariadb --max-allowed-packet=64M -u example_db -p example_db < dump.sql