int mysql_server_init(int argc, char **argv, char
**groups)
This function initializes the MySQL client library, which must
be done before you call any other MySQL function. However,
mysql_server_init()
is
deprecated and you should call
mysql_library_init()
instead.
See Section 23.8.7.40, “mysql_library_init()”.
To avoid memory leaks after the application is done using
the library (for example, after closing the connection to
the server), be sure to call
mysql_server_end()
(or
mysql_library_end()
)
explicitly. This enables memory managment to be performed to
clean up and free resources used by the library. See
Section 23.8.7.39, “mysql_library_end()”.
mysql_server_init apparently does not copy the strings you supply it. It simply makes use of the pointers. Be sure that any string variables you put in place of the server arguments persist throughout your program or some functions may fail. Here's an example:
char Data[] = "--datadir=c:/blah/blah/blah/";
const char *server_args[] =
{
"this_program",
Data,
"--skip-innodb"
};
mysql_server_init(etc...);
Now the function ends and the 'Data' var is obliterated. mysql_server_init will execute correctly, but later, in a different function mysql_real_connect will fail mysteriously, claiming it can't find the specified database.
Seems simple, even obvious. I won't mention how long it took me to trace the problem in my program...