c++ - Why LOAD DATA LOCAL INFILE will work from the CLI but not in application? -
the problem:
my c++ application connects mysql server, reads first/header line of each db export.txt, makes create table statement prepare import , executes against database (no problem that, table appears intended) -- when try , execute load data local infile import data newly created table, error "the used command not allowed mysql version". but, works on cli! when execute command on cli using mysql -u <user> -p<password> -e "load data local infile 'myfile.txt' table mytable fields terminated '|' lines terminated '\r\n';" works flawlessly?
the situation:
my company gets large quantity of database exports (160 files/10gb of .txt files '|' delimited) our vendors on monthly basis have replace old vendor lists. working on smallish c++ app deal on work desktop. application meant set required tables, import data, execute series of intermediate queries against multiple tables assemble information in series of final tables, exported , uploaded production environment, use in companies e-commerce website.
my setup:
ubuntu 12.04
mysql server v. 5.5.29 + mysql command line client
linux gnu c++ compiler
libmysqlcppconn installed , have required mysqlconn library linked in.
i have overcome/tried following issues/combinations:
1.) have discovered (the hard way) load data [local] infile statements must enabled in config -- have "local-infile" option set in configuration files both client , server. (fixed updating /etc/mysql/my.cnf "local-infile" statements client , server. note: have used --local-infile=1 restart mysql-server, local dev environment wanted turned on permanently)
2.) load data local infile seems fail perform import (from cli) if target import file not have execute permissions enabled (fixed chmod +x target_file.txt)
3.) using mysql root account in application code (because localhost, not production , particular program never run on production server.)
4.) have tried executing compiled binary program using sudo command (no change, same error "the used command not allowed mysql version")
5.) have tried changing ownership of binary file normal login root (no change, same error "the used command not allowed mysql version")
6.) know libcppmysqlconn working because able connect , perform create table call without problem, , can other queries , execute statements
what missing? suggestions? in advance :)
after diligent trial , error working /etc/mysql/my.cfg file (i know permissions issue because works on command line, not connector) , after googling , finding alley tech support posts i've come conclude mysql c++ connector did not (for whatever reason) decide implement ability developers able allow local-infile=1 option c++ connector.
apparently people have been able hack/fork mysql c++ connector expose functionality, no 1 posted source code -- said worked. apparently there workaround in mysql c api after initialize connection use this:
mysql_options( &mysql, mysql_opt_local_infile, 1 ); which apparently allows load data local infile statements work mysql c api.
here reference articles lead me conclusion:
1.) how can native c api connection structure mysql connector/c++?
2.) mysql 5.5 load data infile permissions
3.) http://osdir.com/ml/db.mysql.c++/2004-04/msg00097.html
essentially if want ability use load data local infile functionality programmatic connector api -- have use mysql c api or hack/fork existing mysql c++ api expose connection structure. or stick executing load data local infile command line :(
Comments
Post a Comment