Bug #43408 "Forcing shutdown of 1 plugins" overrides actual error message in libmysqld
Submitted: 5 Mar 2009 11:01 Modified: 5 Mar 2009 11:31
Reporter: Hartmut Holzgraefe Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S3 (Non-critical)
Version:mysql-5.1.31 OS:Linux
Assigned to: CPU Architecture:Any

[5 Mar 2009 11:01] Hartmut Holzgraefe
Depending on the stage that mysql_library_init()/mysql_server_init() fails in a following call to mysql_error() will not return the error description for the actual problem but "[Warning] Forcing shutdown of 1 plugins". Looks as if this warning is raised during cleanup of the failed embedded server start attempt and is overwriting the previous error message describing the actual problem that lead to the initialization failure.

How to repeat:
Pass a nonexisting command line option to mysql_(library|server)_init() or provide it with a my.cnf file with an invalid option. When calling 
mysql_error(NULL) after the failed _init call you'll get 

  [Warning] Forcing shutdown of 1 plugins

as error text instead of the expected

  [Error] unknown option '--foobar'

This makes tracking the actual reason for the initialization failure rather hard.

Suggested fix:
Make sure that the first error encountered during server initialization is given back by mysql_error() after a call to mysql_(server|library)_init(), not the last one.
[5 Mar 2009 11:28] Hartmut Holzgraefe
The following simple test program can be used to reproduce the problem.

When linked against a MySQL 4.1 embedded server library it terminates with

  090305 12:25:14 [ERROR] mysql_embedded: unknown option '--foobar'

but when linked against MySQL 5.1 libmysqld it reports 

  Error initializing the server: 2000 Forcing shutdown of 3 plugins

(the number of plugins may vary depending on server compile options)

#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>

static char *server_options[] = { "mysql_test", "--foobar", NULL};
int num_elements = (sizeof(server_options)/ sizeof(char *)) - 1;
static char *server_groups[] = { "libmysqld_server", "libmysqld_client", NULL};

int main(void)
  if(mysql_library_init(num_elements, server_options, server_groups)) {
    fprintf(stderr, "Error initializing the server: %d %s\n", mysql_errno(NULL), mysql_error(NULL));

  printf("Initialized the server\n");

  return 0;
[17 Dec 2010 9:55] Hartmut Holzgraefe
With 5.5 the error message now is

  Error initializing the server: 2000 mysql_embedded: Shutdown complete

so at least a little less confusing than the "Forcing shutdown of $x plugins" one, but still the real error message seems to be overwritten .... :(