mysql版本5.5.29,是通过软件中心安装的。
刚装完时,在mysql命令行下,load data local infile时 报错信息是iThe used command is not allowed with this MySQL version
然后,将/etc/mysql/my.cnf配置文件加入--local-infile=1后,在mysql命令行下执行load data local infile 成功。
但是通过C api的mysql_query函数执行load data local infile时不成功。代码如下:
res2 = mysql_query(conn_ptr,"load data local infile \'/home/tcz/test.csv\' into table test fields terminated by \',\' lines terminated by \'\n\'")    ;
fprintf(stderr,"Load error %d:%s\n",mysql_errno(conn_ptr),mysql_error(conn_ptr));用api函数mysql_errno和mysql_error打印出的错误代码如下
Load error 1148:The used command is not allowed with this MySQL version
跟当初没有配置--local-infile=1时在mysql下执行时的错误信息一样。
配置后,为何在mysql命令行下可以执行,而通过C api不能执行呢? 谢谢各位,本人刚刚学习mysql ,敬请指教。

解决方案 »

  1.   

    上网查了一下,发现可能是API函数mysql_real_connect 最后一个参数的问题,将最后一个参数从0改为CLIENT_LOCAL_FILES,网上说这是开启了load data local的功能,重新编译运行。仍然报错:
    error 2027:Malformed packet,网上说是残缺信息包错误,不知道这是什么意思,也没找到处理方法。继续求指教。谢谢!
      

  2.   

    试试
    res2 = mysql_query(conn_ptr,"set global LOAD DATA LOCAL =1;load data local infile \'/home/tcz/test.csv\' into table test fields terminated by \',\' lines terminated by \'\n\'")    ;可能原因
    If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:ERROR 1148: The used command is not allowed with this MySQL version
    服务端和客户端都要设置
      

  3.   

    谢谢回复,我之前已经把/etc/mysql/my.sql 的客户端和服务器都设置成了local-infile=1。按照您的方法:加上"set global LOAD DATA LOCAL=1;"这一句,重新编译运行了一下好像说是sql语法有问题。
    error 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LOAD DATA LOCAL=1;load data local infile '/home/tcz/test.csv' into table test fi' at line 1
      

  4.   

    下述选项都设置了local-infile=1, 仍不好用吗?
    [mysql]
    [client]那么,你可以从你发起的sql语句中去掉:set global LOAD DATA LOCAL=1这一段。
    在创建连接之前,调用API:
    显式调用mysql_options (...MYSQL_OPT_LOCAL_INFILE,0), 具体这个常量名可能略有变化,修改一下。
    然后看看是否能够了运行,
    如果仍然出错,应该是mysql的源码做了手脚。