SQL Error (2027): Malformed packet I have a mysql database (Version 5.6.23-log running on windows) that is set up for use with Teamcity. When running a command against it using HeidiSQL I am getting an error:


  SQL Error (2027): Malformed packet 


This error only occurs if the result set is more than a certain number of rows (using LIMIT 14561 rows works, 14562 gives this error).

I believe this error is not due to Heidi since TeamCity is failing to start when running the same command.

I assume it is something to do with the data size becoming too large and something failing but I can't find any way to identify more specifically what the problem is and thus how to fix it. 

If anybody can tell me what I can do to prevent this problem or at the very least how I might be able to better diagnose this problem I'd be most grateful.
My guess would be that you have TEXT/BLOB data and that the row data in the 14562 row is bigger than your current MySQL Packet, which is sized by max_allowed_packet.

MySQL Perspective

You need to reserve more space for max_allowed_packet


Jul 29, 2013 : Max_packet_allowed setting for Windows 7
Jul 03, 2013 : What max_allowed_packet is big enough, and why do I need to change it?
Jun 12, 2012 : MySQL Error Reading Communication Packets


Your InnoDB Redo Logs (sized by innodb_log_file_size) may need to be increased as well. I first learned of it (in relation to the MySQL Packet) from ServerFault. I refer to that ServerFault post in some of my posts:


Apr 27, 2011 : Changed max_allowed_packet and still receiving &#39;Packet Too Large&#39; error 
Aug 01, 2011 : How does max_allowed_packet affect the  backup and restore of a database?


I would max out the max_allowed_packet to 1G and resize your redo logs to 1.5G

[mysqld]
max_allowed_packet = 1G
innodb_log_file_size = 1536M


Next, run this to purge all transactions out of the redo logs:

mysql&gt; SET GLOBAL innodb_fast_shutdown = 0;


Then, restart mysql (which is required).

Note to everyone running MySQL 5.5 and prior

MySQL 5.6 will handle resizing logs for you when restarting. Previous versions of MySQL require that you do that manually. Your steps after changing my.cnf and setting innodb_fast_shutdown to 0, you would do the following

service mysql stop
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
service mysql start


HeidiSQL Perspective

One very common complaint is Error 2027, particularly with using LOAD DATA INFILE

Some have suggested using older versions of libmysql.dll


HeidiSQL 8.1 released
sql error(2007) Malformed packet


Some suspect a character set issue : Error Code: 2027 Malformed packet

GIVE IT A TRY !!!