Bug #1859 mysql_init bug under CYGWIN
Submitted: 17 Nov 2003 4:55 Modified: 16 Dec 2003 8:26
Reporter: Fabrice Marchal Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.16 OS:Windows (Win2K)
Assigned to: CPU Architecture:Any

[17 Nov 2003 4:55] Fabrice Marchal
I use the latest cygwin release ( and the MYSQL server for windows,
release 4.0.16. All my MYSQL client programs crashed. It seems that there
is a bug with mysql_init (see code below). Note that my code was compiling
with previous releases, I suspect it might also be a problem with GCC3.3.1.
I was not able to use gdb to track the bug since GDB reports a corrupted stack.
I use g++ -Lc:/mysq/lib/debug -lmySQL to compile the programs.
Note: the following code crashes BEFORE calling mysql_real_connect .
In fact it crashes when returning from the Test() constructor. It seems
that the fork/thread management in mysql_init() is messing something up.


How to repeat:
This simple test shoud crash:

int main( int argc, char** argv ){
    Test* mytest = new Test();

where class Test looks like this:
#include "mysql.h"
class Test{
MYSQL* mysql_handle;
Test(){ mysql_handle = mysql_init(NULL) ; }
void connect(){
mysql_real_connect( mysql_handler( ........ ) ; }
[1 Dec 2003 14:38] Dean Ellis
Copying comments from duplicate issue #1979:

Description: I dont know if this is a problem of mysql, g++ or
cygwin but the following simple code keeps crashing with g++3.3.1
Platform: cygwin-1.5.5, mysql 3.23 and mysql 4.1 as well
Note that the code does not crash if all the mysql_ calls are
made from inside the "main()" block. GDB reports that the crash occurs 
when returning from the Connection() constructor.

How to repeat:
#include "mysql.h"
#include <iostream>

using namespace std;

class Connection{
  MYSQL *mysql;
	mysql = mysql_init( NULL );
	if( mysql == 0 ){
		cerr << "failed to init" << endl;
		exit(-1); }
	mysql_real_connect( mysql, "", "", "", "test", 3306, NULL, 0);

int main( int argc, char** args ){
	Connection con;

Suggested fix:
[13 Dec 2003 18:33] Michael Widenius
A short comment on this issue:

We don't support the MySQL server under cygwin becasue to our knowledge the thread handling under cygwin is not safe and the server works very good with VC++ /Intel  C++ compiler and native Windows threads.

It should however be possible to compile the MYSQL client with cygwin support as long as you have defined -DUNDEF_THREADS_HACK (or not defined -DTHREAD).

Unfortunately we don't have anyone her at MySQL AB that is working actively with  cygwin so we can't help you with this.  We are however willing to look at any patch you can come up with that may fix this problem.

[15 Dec 2003 5:13] Fabrice Marchal
Thanks for your reply. I am not sure I made my point clear enough though:
I am indeed linking against libmySQL.lib that is provided with the
MYSQL Win32 install. The server is not running "under cygwin" per se,
but my client code is compiled under cygwin and linked agains the compiled
libraries provided in the distro. If I understand right, these libs are wrappers
around .DLL lib calls. Doing a "nm" reveals that those libs use PTHREAD but
I am not sure how. So your suggestion is either to fix it myself or
to go for another compiler environment for my own client (e.g. VC++)?
[16 Dec 2003 8:26] MySQL Verification Team
How Monty explained: we can't to help you with Cygwin because currently
nobody works with that stuff at MySQL, the other option you have is to
use VC++ 6.0 which it is our current Windows build stuff.