Too many connections
Ronny Melz <[email protected]> Wed, 1 Jun 2005 02:36:08 +0200
| Newsgroups | gmane.comp.db.mysql.bugs |
|---|---|
| Message-ID | <[email protected]> |
Dear all,
I have a problem with the mysql interface for c, which after a couple of hours
thinking about bad or faulty programming are eliminated with probability
almost 100%.
within a loop, I do a mysql_query(), which is executed and I poll the result
and everything is fine. Up to when max_connections of the mysqld is reached:
each of the queries leaves after executing a sleeping mysql process behind on
the server, which hence throws the "Too many connections" error (or under
certain conditions even a "Can't create TCP/IP socket (24)").
Just because of this problem I recently upgraded mysql (including the
libraries) from 4.0.21 to 4.1.12, but the problem persisted.
Does anybody have an idea of how to solve this problem?
Any suggestions are appreciated.
Best,
Ronny
p.s.: code
#define GET_W_NR \
"select wort_nr from wortliste where wort_bin='%s' limit 1"
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
init...
{
mysql_init(&mysql);
if ( !mysql_real_connect( &mysql, "127.0.0.1", "username", "passwd",
"dbase",
0, "/var/lib/mysql/mysql.sock", 0 ) )
{
fprintf(stderr, "Failed: %s\n", mysql_error(&mysql));
}
if (!(query = (char*) malloc(256*sizeof(char)))) fprintf(stderr, "no
pointer");
}
this is called in a loop and returns with an error after `max_connections`
cycles:
{
sprintf(query, GET_W_NR, refWort);
if ( mysql_query( &mysql, query ) )
{
fprintf(stderr, "query failed: %s\n", mysql_error(&mysql));
return 0;
}
if ( !( res = mysql_store_result( &mysql ) ) )
{fprintf(stderr, "store failed: %s\n", mysql_error(&mysql)); return
0;}
if ( row = mysql_fetch_row( res ) )
ref_word_nr = atoi(row[0]);
else
{fprintf(stderr, "fetch failed: %s\n", mysql_error(&mysql)); return
0;}
mysql_free_result(res);
}
exit...
free(query);
mysql_close(&mysql);
--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/[email protected]