Answer: we need the following line of code:
mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 0 );
inserted between mysql_init() and mysql_real_connect() .
Below is a snippet of C code for reference. Note that the SOCI mysql backend can be fixed with this line of code to make it work.
Tested and works on Mysql 5.5, gcc 4.7.2, Quantal.
#include <mysql.h> #include <stdio.h> main() { MYSQL mysql; mysql_init( &mysql ); mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 0 ); if ( !mysql_real_connect( &mysql,"127.0.0.1","root","open_sasame","tmp_db",0,NULL,0 )) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error( &mysql )); } if ( mysql_query( &mysql, "LOAD DATA LOCAL INFILE '/tmp/junk4.txt' " "INTO TABLE tmp_db.example_tbl FIELDS TERMINATED BY '|' " "LINES TERMINATED BY '\\n'" )) { fprintf( stderr, "ERROR DURING LOAD DATA LOCAL INFILE\n" ); } mysql_close( &mysql ); }
source share