This will create a thread-safe client library @code{libmysqlclient_r}.
@code{--enable-thread-safe-client}. This library is thread safe per
connection. You can let two threads share the same connection as long
as you do the following:
connection. You can let two threads share the same connection with
the following caveats:
@itemize @bullet
@item
Two threads can't send a query to the MySQL at the same time on
Two threads can't send a query to the MySQL server at the same time on
the same connection. In particular, you have to ensure that between a
@code{mysql_query()} and @code{mysql_store_result()} no other thread is using
the same connection.
...
...
@@ -43725,9 +43725,9 @@ Many threads can access different result sets that are retrieved with
@code{mysql_store_result()}.
@item
If you use @code{mysql_use_result}, you have to ensure that no other thread
is asking anything on the same connection until the result set is closed.
is using the same connection until the result set is closed.
However, it really is best for threaded clients that share the same
connection to use @code{mysql_use_result()}.
connection to use @code{mysql_store_result()}.
@item
If you want to use multiple threads on the same connection, you must
have a mutex lock around your @code{mysql_query()} and
...
...
@@ -43741,14 +43741,14 @@ establish and release a mutex lock.
@end itemize
You need to know the following if you have a thread that is calling
MySQL functions, but that thread has not created the connection to the
MySQL functions which did not create the connection to the
MySQL database:
When you call @code{mysql_init()} or @code{mysql_connect()}, MySQL will
create a thread specific variable for the thread that is used by the
debug library (among other things).
If you have in a thread call a MySQL function, before a thread has
If you call a MySQL function, before the thread has
called @code{mysql_init()} or @code{mysql_connect()}, the thread will
not have the necessary thread specific variables in place and you are
likely to end up with a core dump sooner or later.
...
...
@@ -43769,7 +43769,7 @@ specific variables.
@end enumerate
You may get some errors because of undefined symbols when linking your
client with @code{mysqlclient_r}. In most cases this is because you haven't
client with @code{libmysqlclient_r}. In most cases this is because you haven't
included the thread libraries on the link/compile line.
@node libmysqld, , Threaded clients, C
...
...
@@ -43796,22 +43796,22 @@ full-featured MySQL server inside the client application. The
main benefits are increased speed and more simple management for
embedded applications.
The API is identical for the embedded MySQL version and MySQL
The API is identical for the embedded MySQL version and the
client/server version. To change an old threaded application to use the
embedded library, on normall only have to add calls to the following
embedded library, you normally only have to add calls to the following
functions:
@multitable @columnfractions .25 .7
@item @code{mysql_server_init()} @tab Should be called before any other other MySQL function is called, preferably early in the @code{main()} function.
@item @code{mysql_server_end()} @tab Should be called before doing an exit of your program.
@item @code{mysql_thread_init()} @tab Should be called in all threads you are created that will access MySQL.
@item @code{mysql_server_end()} @tab Should be called before your program exits.
@item @code{mysql_thread_init()} @tab Should be called in each thread you create that will access MySQL.
@item @code{mysql_thread_end()} @tab Should be called before calling @code{pthread_exit()}
@end multitable
and link your code with @code{libmysqld.a} instead of @code{libmysqlclient.a}.
Then you must link your code with @code{libmysqld.a} instead of @code{libmysqlclient.a}.
The above @code{mysql_server_xxx} functions are also included in
@code{libmysqld.a} to allow you to change between the embedded and the
@code{libmysqlclient.a} to allow you to change between the embedded and the
client/server version by just linking your application with the right
library. @xref{mysql_server_init}.
...
...
@@ -43823,8 +43823,8 @@ To get a @code{libmysqld} library you should configure MySQL with the
@code{--with-embedded-server} option.
When you link your program with @code{libmysqld}, you must also include
the systemspecific @code{pthread} libraries and some libraries that
@code{mysqld} uses. You can get the full list of libraries by executing
the system-specific @code{pthread} libraries and some libraries that
the MySQL server uses. You can get the full list of libraries by executing
@code{mysql_config --libmysqld-libs}.
The correct flags for compiling and linking a threaded program
...
...
@@ -43835,8 +43835,6 @@ functions in your code.
@subsubsection Restrictions when using the Embedded MySQL Server
The embedded server has the following limitations:
(Some of these limitations can be changed by editing the @code{mysql_embed.h}
include files and recompiling MySQL)
@itemize @bullet
@item
...
...
@@ -43849,6 +43847,9 @@ No stack trace on core dump.
No internal RAID support.
@end itemize
Some of these limitations can be changed by editing the @file{mysql_embed.h}
include file and recompiling MySQL.
@node libmysqld options, libmysqld TODO, libmysqld restrictions, libmysqld
@subsubsection Using option files with the embedded server
...
...
@@ -43902,13 +43903,13 @@ designed to give enough details to understand the problem,
without the clutter that is a necessary part of a real
application.
To try out the example, create an @file{example} directory
To try out the example, create an @file{test_libmysqld} directory
at the same level as the mysql-4.0 source directory. Save
the @file{example.c} source and the @file{GNUmakefile} in the
directory, and run GNU @file{make} from inside the @file{example}
the @file{test_libmysqld.c} source and the @file{GNUmakefile} in the
directory, and run GNU @file{make} from inside the @file{test_libmysqld}
directory.
@file{example.c}
@file{test_libmysqld.c}
@example
/*
* A simple example client, using the embedded MySQL server library