Max allowed packet (MySQL)
[1]:
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 master replication server to a slave.
The largest possible packet that can be transmitted to or from a MySQL 8.0 server or client is 1GB = 2^30 = 1.073.741.824
When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.
Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.
Actuele waardes uitlezen
Je kunt de waarde van max_allowed_packet
uitlezen middels bv.:
show variables where variable_name like "max_a%"; +--------------------+----------+ | Variable_name | Value | +--------------------+----------+ | max_allowed_packet | 67108864 | +--------------------+----------+ 1 row in set (0.00 sec)
Waarschijnlijk is de waarde gegeven in bytes, omdat het geen afgerond getal is en het sommetje verbazend goed uitkomt:
* 67108864/1024 = 65.536 KB * 67108864/1024^2 = 64 MB
De maximale waarde is 1GB:
* 1 GB = 2^10 MB = 1024^1 KB = 1.024 MB * = 2^20 KB = 1024^2 KB = 1.048.576 KB * = 2^30 B = 1024^3 B = 1.073.741.824 B
Het probleem is echter, dat server, client en mysqldump hun eigen versie hebben van deze parameter. Ik weet niet welke versie bovenstaand commando geeft.
mysql
Zoals hierboven al geschreven: Server, client & mysqldump hebben elk hun eigen versie van deze parameter. Je kunt on-the-fly een aangepaste waarde meegeven bij gebruik van mysql
. Handig voor debuggen. Wat man mysql
hierover zegt:
--max-allowed-packet=value The maximum size of the buffer for client/server communication. The default is 16MB, the maximum is 1GB.
Casus: Storing mysqldump (Juni 2020)
Oh oh:
mysqldump example_com > example_com-20200611.sql mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `wp_options` at row: 1929
LET OP: Dit is een storing in mysqldump! Niet in de server of de mysql-client! Deze entiteiten hebben alledrie hun eigen max_allowed_packet-max. waardes
On-the-fly
Dit werkte, en is een goede manier om eea. te checken:
mysqldump --max_allowed_packet=1024MB example_com > example_com.sql
Aanpassing
Aanpassing in /etc/mysql/my.cnf voor systeemwijde aanpassing:
########################################################################### # Strompf - [mysqldump] ########################################################################### # [mysqldump] max_allowed_packet=1024MB
Gevolgd door sudo service mysql restart
om het direct te actueren.
Casus: Importeren lukt niet (okt. 2020)
Probleem
Ik kan een db-dump afkomstig van een Cloudways-MariaDB-db niet importeren:
mysql wp_tmp < kbb-20201029.sql ERROR 2006 (HY000) at line 813: MySQL server has gone away
Aanvullende gegevens & tests
- Het is niet zeker op het probleem ligt by
max_allowed_packet
, al was dat in het verleden wel het geval - Waarde
max_allowed_packet
op client: 64MB - Waarde
max_allowed_packet
op client: 512MB (536870912 bytes) - Test:
mysql --max-allowed-packet=512MB wp_tmp < kbe-20201029.sql
- Zelfde foutmelding! - Test:
mysql --max-allowed-packet=1024MB wp_tmp < kbe-20201029.sql
- Zelfde foutmelding!
/etc/mysql/my.cnf aangepast
- In
/etc/mysql/my.cnf
was de waarde voor deze variabele niet aangepast - Nu ingesteld op 512MB + server herstart
mysql --max-allowed-packet=1024MB wp_tmp < kbe-20201029.sql
→ Gelukt!mysql wp_tmp < kbe-20201029.sql
→ Gelukt!mysql --max-allowed-packet=64MB wp_tmp < kbe-20201029.sql
→ Gelukt!
Conclusies
- Er lijken helemaal geen verschillende versies te zijn van
max_allowed_packet
- De waarde in/etc/mysql/my.cnf
in de sectie[mysqld]
, lijkt alles te bepalen - Parameter
--max-allowed-packet
lijkt geen enkel verschil te maken.