Description:
"Malformed communication packet" and "Commands out of sync" error occurred when I run a program compiled against libmysqld(version 5.6.14), the following is the error log:
----------------------------------------------
starting server...
mysql_embedded: Table 'mysql.plugin' doesn't exist
connect to server...
2013-11-15 12:25:38 7fd4beb80720 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-11-15 12:25:38 7fd4beb80720 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-11-15 12:25:38 7fd4beb80720 InnoDB: Error: Fetch of persistent statistics requested for table "mydb"."mytable" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
failed to execute stmt:Malformed communication packet.
failed to store result:Commands out of sync; you can't run this command now
result: 0 rows
failed to execute stmt:Malformed communication packet.
failed to store result:Commands out of sync; you can't run this command now
result: 0 rows
closing stmt...
closing conneciton...
shutdown server...
----------------------------------------------
and the expected result should be:
----------------------------------------------
starting server...
result: 2 rows
id = 1, col = 100, length = 4
id = 1, col = 200, length = 4
result: 1 rows
id = 2, col = 300, length = 4
closing stmt...
closing conneciton...
shutdown server...
----------------------------------------------
while I compiled the program against libmysqld(version 5.6.11), correct results returned but with same warning as 5.6.14:
----------------------------------------------
starting server...
mysql_embedded: Table 'mysql.plugin' doesn't exist
connect to server...
2013-11-15 12:10:33 7f17a6197720 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-11-15 12:10:33 7f17a6197720 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-11-15 12:10:33 7f17a6197720 InnoDB: Error: Fetch of persistent statistics requested for table "mydb"."mytable" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
result: 2 rows
id = 1, col = 100, length = 4
id = 1, col = 200, length = 4
result: 1 rows
id = 2, col = 300, length = 4
closing stmt...
closing conneciton...
shutdown server...
----------------------------------------------
so, both 5.6.11 and 5.6.14 report warinings of certain system tables not exists, while 5.6.14 report errors when executing prepared statements.
How to repeat:
1. cmake options:
CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
CXX=g++
CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
export CFLAGS CXX CXXFLAGS
cmake . \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DSYSCONFDIR:PATH=/u01/mysql/ \
-DCMAKE_INSTALL_PREFIX:PATH=/u01/mysql \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=ON \
-DWITH_DEBUG:BOOL=OFF \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_BIG_TABLES:BOOL=ON \
-DWITH_FAST_MUTEXES:BOOL=ON \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \
-DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam \
-DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_EXTRA_CHARSETS=all \
-DENABLED_ASSEMBLER:BOOL=ON \
-DWITH_EMBEDDED_SERVER:BOOL=ON \
-DINSTALL_LAYOUT:STRING=STANDALONE
2. make -j16 && make install
3. in /u01/mysql
g++ test.c `bin/mysql_config --libmysqld-libs --include`
./a.out
test.c and my_embedded.cn will be attached, see comment.
Suggested fix:
more #ifdef(s) should be added around certain code blocks