List:Internals« Previous MessageNext Message »
From:Andrej van der Zee Date:March 24 2009 5:18am
Subject:LOAD DATA LOCAL INFILE in background thread brings down MySQL server
View as plain text  
Hi,

I am wondering why the LOAD DATA LOCAL INFILE command is not working
from my custom background thread in MySQL. I read the documentation
about the command carefully and set up the client and server to be
able have this command supported. It works perfectly fine from the
test program below. But if I use the same commands in my background
thread in the MySQL server, then the call to mysql_query() hangs and
eventually fails crashing the whole MySQL server. Issuing other
queries in the background thread work perfectly fine, it seems to be
just this LOAD DATA LOCAL INFILE command. Any ideas?

Please help!
Andrej


#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
  MYSQL *conn;

  static const char * query = "LOAD DATA LOCAL INFILE
'/dev/shm/mbrace_infile.txt' INTO TABLE request_mysql FIELDS
TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"' LINES TERMINATED BY
'\\n'";

  for (int i=0; i<100; ++i)
  {
    conn = mysql_init(NULL);
    if (!mysql_real_connect(conn, "mbrace3", "mbrace", "mbrace",
"mbracelog", 3306, 0, CLIENT_LOCAL_FILES))
    {
      fprintf(stderr, "Failed to connect to mbracelog database: %s",
mysql_error(conn));
      return 1;
    }

    if (mysql_options(conn, MYSQL_OPT_LOCAL_INFILE, NULL))
    {
      fprintf(stderr, "Failed to set mysql option
MYSQL_OPT_LOCAL_INFILE: %s", mysql_error(conn));
      mysql_close(conn);
      return 1;
    }

    if (mysql_query(conn, query))
    {
      fprintf(stderr, "Failed to execute query: %s: %s", query,
mysql_error(conn));
      mysql_close(conn);
      return 1;
    }

    mysql_close(conn);
  }

  return 0;
}
Thread
LOAD DATA LOCAL INFILE in background thread brings down MySQL serverAndrej van der Zee24 Mar
  • Re: LOAD DATA LOCAL INFILE in background thread brings down MySQL serverAndrej van der Zee24 Mar
  • Re: LOAD DATA LOCAL INFILE in background thread brings down MySQL serverKristian Nielsen24 Mar
    • Re: LOAD DATA LOCAL INFILE in background thread brings down MySQL serverAndrej van der Zee24 Mar
      • Re: LOAD DATA LOCAL INFILE in background thread brings down MySQL serverAndrej van der Zee25 Mar
Re: LOAD DATA LOCAL INFILE in background thread brings down MySQL serverAndrej van der Zee25 Mar