Skip navigation links

User Comments

Posted by Dan Pickett on October 3 2003 8:44am[Delete] [Edit]

I'm currently working on embedding this into a dll that is compiled with Visual C++. I found the following useful to make this compile.

It is necessary to ensure winsock.h is included before mysql.h. This is because SOCKET is defined in winsock.h and is used by mysql_com.h and mysql.h includes mysql_com.h.

I noticed that winsock.h is included in mysql.h but is wrapped inside a #ifdef. I suppose another alternate would be to figure out why this isn’t being entered and resolve it.

Example,
#ifdef __LCC__
#include <winsock.h> /* For windows */
#endif

As we can see, if __LCC__ were defined there would be no reason to include winsock.h. If this is a bug someone should report it.

Also, when compiling this for an MFC application, I found it necessary to turn off/disable precompiled headers. For some reason, including winsock.h wasn’t being accepted when called after #include “stdafx.h”. After disabling precompiled headers the code compiled; hmmm… maybe that is another bug.

One reason for my post is a search on the internet suggested others were unable to compile this for the same reason I was unable.

Posted by [name withheld] on March 6 2004 5:30am[Delete] [Edit]

For the simple embedded server example code in documents, there is a bug in the Makefile. You have to put "-lstdc++" to gcc command line to solve the problem, or after you type make, you'll get a lot of "undefined reference" errors.

Posted by Michael London on April 11 2005 10:36pm[Delete] [Edit]

On Windows, I had trouble getting the mysql embedded server to go passed mysql_server_init() function. After many hours of fiddling with the settings, I discovered that if you have the mysql-service running in the background (usually mysqld-nt.exe) the call to mysql_server_init() will fail! I have disabled the service from starting up... I don't know if this is a bug or a sharing violation with mysql service (seeing as that's also an embedded server!?) or I need to take some extra steps before running my exe, either way, killing the mysql service isn't the ideal fix.

Posted by Dave Dyer on October 26 2005 4:12am[Delete] [Edit]

I can't speak for later releases yet, but for 4.1 here
are some hard won tips:

the embedded server still reads c:\my.cnf and must find
enough initialization there under the keys you've specified
(ie [server]) to make it happy. It will need to find at
least the datadir and language dir. This default behavior
makes it hard to develop a really standalone embedded
application - it really wants to parasitize a regular mysql
installation.

The parser for my.cnf requires path names with
forward slashes even on windows.

Any failures in the initialization process cause a silent
and immediate exit. I only figured out what was going on
by downloading the source and building a complete debugging
environment.

Posted by Jiye Zeng on April 10 2006 5:57am[Delete] [Edit]

After many try-n-errors, I made it to embed MySQL with a scripting language (http://www.zegraph.com/z-script/mysql-reference.html). You can find the source code at http://www.zegraph.com/z-script/src/mysql.cpp. Here are a few points that I think may be helpful for those having problems:

1. Use the same compiling flags for libary and program.

I had problem with linking the distribulted library by VC6++. So I compiled static libraries acoording to flags in distributed project files. For libmysald, I used

WIN32,NDEBUG,_WINDOWS,SIGNAL_WITH_VIO_CLOSE,HAVE_DLOPEN,EMBEDDED_LIBRARY,HAVE_INNOBASE_DB,DBUG_OFF,__WIN__

And for the program I used
WIN32,NDEBUG,_CONSOLE,_MBCS,_WINDOWS,SIGNAL_WITH_VIO_CLOSE,HAVE_DLOPEN,EMBEDDED_LIBRARY,HAVE_INNOBASE_DB,DBUG_OFF,__WIN__

2) Use similar arguments as follows to initialize the server

char *server_groups[] = { "client", "server", 0 };
char *server_options[] = { "mysql_embedded", "--defaults-file=e:\\my.ini"};

And in "my.ini" groups of [client] and [server] must exist, somting like:

[client]
default-character-set=utf8
[server]
basedir=e:/db
datadir=e:/db/data
default-character-set=utf8

3) Contents in the distributed share directory should be copied to basedir for MySQL to find charactersets and etc.

Posted by Apurba Nath on August 21 2012 9:43am[Delete] [Edit]

will also need -lrt in the GNUmakefile for resolving clock_gettime in my_getsystime.c etc