This will create a thread-safe client library @code{libmysqlclient_r}.
This will create a thread-safe client library @code{libmysqlclient_r}.
@code{--enable-thread-safe-client}. This library is thread safe per
@code{--enable-thread-safe-client}. This library is thread safe per
connection. You can let two threads share the same connection as long
connection. You can let two threads share the same connection with
as you do the following:
the following caveats:
@itemize @bullet
@itemize @bullet
@item
@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
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
@code{mysql_query()} and @code{mysql_store_result()} no other thread is using
the same connection.
the same connection.
...
@@ -43725,9 +43725,9 @@ Many threads can access different result sets that are retrieved with
...
@@ -43725,9 +43725,9 @@ Many threads can access different result sets that are retrieved with
@code{mysql_store_result()}.
@code{mysql_store_result()}.
@item
@item
If you use @code{mysql_use_result}, you have to ensure that no other thread
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
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
@item
If you want to use multiple threads on the same connection, you must
If you want to use multiple threads on the same connection, you must
have a mutex lock around your @code{mysql_query()} and
have a mutex lock around your @code{mysql_query()} and
...
@@ -43741,14 +43741,14 @@ establish and release a mutex lock.
...
@@ -43741,14 +43741,14 @@ establish and release a mutex lock.
@end itemize
@end itemize
You need to know the following if you have a thread that is calling
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:
MySQL database:
When you call @code{mysql_init()} or @code{mysql_connect()}, MySQL will
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
create a thread specific variable for the thread that is used by the
debug library (among other things).
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
called @code{mysql_init()} or @code{mysql_connect()}, the thread will
not have the necessary thread specific variables in place and you are
not have the necessary thread specific variables in place and you are
likely to end up with a core dump sooner or later.
likely to end up with a core dump sooner or later.
...
@@ -43769,7 +43769,7 @@ specific variables.
...
@@ -43769,7 +43769,7 @@ specific variables.
@end enumerate
@end enumerate
You may get some errors because of undefined symbols when linking your
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.
included the thread libraries on the link/compile line.
@node libmysqld, , Threaded clients, C
@node libmysqld, , Threaded clients, C
...
@@ -43796,22 +43796,22 @@ full-featured MySQL server inside the client application. The
...
@@ -43796,22 +43796,22 @@ full-featured MySQL server inside the client application. The
main benefits are increased speed and more simple management for
main benefits are increased speed and more simple management for
embedded applications.
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
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:
functions:
@multitable @columnfractions .25 .7
@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_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_server_end()} @tab Should be called before your program exits.
@item @code{mysql_thread_init()} @tab Should be called in all threads you are created that will access MySQL.
@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()}
@item @code{mysql_thread_end()} @tab Should be called before calling @code{pthread_exit()}
@end multitable
@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
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
client/server version by just linking your application with the right
library. @xref{mysql_server_init}.
library. @xref{mysql_server_init}.
...
@@ -43823,8 +43823,8 @@ To get a @code{libmysqld} library you should configure MySQL with the
...
@@ -43823,8 +43823,8 @@ To get a @code{libmysqld} library you should configure MySQL with the
@code{--with-embedded-server} option.
@code{--with-embedded-server} option.
When you link your program with @code{libmysqld}, you must also include
When you link your program with @code{libmysqld}, you must also include
the systemspecific @code{pthread} libraries and some libraries that
the system-specific @code{pthread} libraries and some libraries that
@code{mysqld} uses. You can get the full list of libraries by executing
the MySQL server uses. You can get the full list of libraries by executing
@code{mysql_config --libmysqld-libs}.
@code{mysql_config --libmysqld-libs}.
The correct flags for compiling and linking a threaded program
The correct flags for compiling and linking a threaded program
...
@@ -43835,8 +43835,6 @@ functions in your code.
...
@@ -43835,8 +43835,6 @@ functions in your code.
@subsubsection Restrictions when using the Embedded MySQL Server
@subsubsection Restrictions when using the Embedded MySQL Server
The embedded server has the following limitations:
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
@itemize @bullet
@item
@item
...
@@ -43849,6 +43847,9 @@ No stack trace on core dump.
...
@@ -43849,6 +43847,9 @@ No stack trace on core dump.
No internal RAID support.
No internal RAID support.
@end itemize
@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
@node libmysqld options, libmysqld TODO, libmysqld restrictions, libmysqld
@subsubsection Using option files with the embedded server
@subsubsection Using option files with the embedded server
...
@@ -43902,13 +43903,13 @@ designed to give enough details to understand the problem,
...
@@ -43902,13 +43903,13 @@ designed to give enough details to understand the problem,
without the clutter that is a necessary part of a real
without the clutter that is a necessary part of a real
application.
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
at the same level as the mysql-4.0 source directory. Save
the @file{example.c} source and the @file{GNUmakefile} in the
the @file{test_libmysqld.c} source and the @file{GNUmakefile} in the
directory, and run GNU @file{make} from inside the @file{example}
directory, and run GNU @file{make} from inside the @file{test_libmysqld}
directory.
directory.
@file{example.c}
@file{test_libmysqld.c}
@example
@example
/*
/*
* A simple example client, using the embedded MySQL server library
* A simple example client, using the embedded MySQL server library