Bug #70917 mysql.plugin' doesn't exist and malformed communication packet in libmysqld
Submitted: 15 Nov 2013 5:50 Modified: 5 Dec 2013 18:24
Reporter: Guangpu Feng Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S2 (Serious)
Version:5.6 OS:Linux
Assigned to: CPU Architecture:Any
Tags: embedded, libmysqld

[15 Nov 2013 5:50] Guangpu Feng
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
[15 Nov 2013 5:52] Guangpu Feng
my_embedded.cnf

Attachment: my_embedded.cnf (application/octet-stream, text), 1015 bytes.

[15 Nov 2013 5:52] Guangpu Feng
test program

Attachment: test.c (application/octet-stream, text), 3.32 KiB.

[15 Nov 2013 9:20] Guangpu Feng
After I disabled innodb_stats_persistent,these errors still occurred:

mysql_embedded: Table 'mysql.plugin' doesn't exist
2013-11-15 17:18:41 7f42b1cd7720 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.

and for mysql 5.6.14, "Commands out of sync; you can't run this command now" error is still reported
[19 Nov 2013 19:34] Sveta Smirnova
Thank you for the report.

Have you installed mysql database prior running the server? If you have old installation, did you run mysql_upgrade on it?
[4 Dec 2013 4:32] Guangpu Feng
Sveta Smirnova

these three directories are empty before ./a.out is executed
data_embedded run_embedded tmp_embedded
[5 Dec 2013 18:24] Sveta Smirnova
Thank you for the feedback.

"Malformed communication packet" is duplicate of bug #70664

Regarding to errors about tables in mysql database this happens, because you did not installed system tables using mysql_install_db script.