MySQL :: MySQL 8.4 C API Developer Guide :: 5.4.45 mysql_library_init() (original) (raw)
5.4.45 mysql_library_init()
int
mysql_library_init(int argc,
char **argv,
char **groups)
Description
Call this function to initialize the MySQL client library before you call any other MySQL function.
Note
To avoid memory leaks after the application is done using the library (for example, after closing the connection to the server), be sure to callmysql_library_end() explicitly. This enables memory managment to be performed to clean up and free resources used by the library. SeeSection 5.4.44, “mysql_library_end()”.
In a nonmultithreaded environment, the call tomysql_library_init() may be omitted, because mysql_init() invokes it automatically as necessary. However,mysql_library_init() is not thread-safe in a multithreaded environment, and thus neither is mysql_init(), which callsmysql_library_init(). You must either callmysql_library_init() prior to spawning any threads, or else use a mutex to protect the call, whether you invokemysql_library_init() or indirectly throughmysql_init(). Do this prior to any other client library call.
The argc
, argv
, andgroups
arguments are unused. In older MySQL versions, they were used for applications linked against the embedded server, which is no longer supported. The call now should be written asmysql_library_init(0, NULL, NULL).
#include <mysql.h>
#include <stdlib.h>
int main(void) {
if (mysql_library_init(0, NULL, NULL)) {
fprintf(stderr, "could not initialize MySQL client library\n");
exit(1);
}
/* Use any MySQL API functions here */
mysql_library_end();
return EXIT_SUCCESS;
}
Return Values
Zero for success. Nonzero if an error occurred.