想连上mysql数据库,然后执行一句 load data file, 编译后运行 发现reads_info表中 没load进去 C++代码如下: int main(int argc,  char *argv[]) 
{ MYSQL mysql; 
mysql_init(&mysql); 
mysql_real_connect(&mysql,"localhost","root","******","reads_fa",0,"",0); 
mysql_query(&mysql,"load data infile '/var/ftp/pub/reads_fa/reads_sql' into table reads_info"); 
mysql_close(&mysql); }

解决方案 »

  1.   

    test.cpp #include <vector> 
    #include <dirent.h> 
    #include <string> 
    #include <iterator> 
    #include <fstream> 
    #include <iostream> 
    #include <ext/hash_map> 
    #include <time.h> 
    #include <mysql/mysql.h> 
    #include <algorithm> 
    #include <iomanip> 
    using std::string; 
    using std::vector; 
    using std::cout; 
    using std::cin; 
    using std::endl; 
    using std::ofstream; 
    using std::ifstream; 
    using std::setw; 
    using __gnu_cxx::hash_map; 
    int main(int argc,  char *argv[]) 
    { MYSQL mysql; 
    mysql_init(&mysql); 
    mysql_real_connect(&mysql,"localhost","root","******","reads_fa",0,"",0); 
    mysql_query(&mysql,"load data infile '/var/ftp/pub/reads_fa/reads_sql' into table reads_info"); cout < <mysql_ping(&mysql) < <"\n"; 
    cout < <mysql_error(&mysql) < <"\n"; 
    mysql_close(&mysql); } root@ubuntu:/var/www# g++ -I/usr/include/mysql/ -L/usr/lib/mysql/ -lmysqlclient -lz -lm  -o map test.cpp 
    root@ubuntu:/var/www# ./map 

    MySQL server has gone away mysql> select * from reads_info;
    Empty set (0.00 sec)mysql> 
    C++是想 把 data file load 到 reads_info表中, 但是不成功!
      

  2.   

    后来 怕是 load执行时间 太长, 把 mysql_query(&mysql,"load data infile '/var/ftp/pub/reads_fa/reads_sql' into table reads_info"); 改为 mysql_query(&mysql,"select * from reads_info);int main(int argc,  char *argv[]) 
    { MYSQL mysql; 
    mysql_init(&mysql); 
    mysql_real_connect(&mysql,"localhost","root","******","reads_fa",0,"",0); 
    mysql_query(&mysql,"select * from reads_info);
    cout < <mysql_ping(&mysql) < <"\n"; 
    cout < <mysql_error(&mysql) < <"\n"; 
    mysql_close(&mysql); } 结果一样root@ubuntu:/var/www# g++ -I/usr/include/mysql/ -L/usr/lib/mysql/ -lmysqlclient -lz -lm  -o map test.cpp 
    root@ubuntu:/var/www# ./map 

    MySQL server has gone away 
      

  3.   

    sql 没有成功执行,
    查下原因吧,和load data 没有关系
      

  4.   

    现在就是不知道 什么原因,查了很久。cout < <mysql_ping(&mysql) < <"\n"; 
    cout < <mysql_error(&mysql) < <"\n"; 
    对应输出1 
    MySQL server has gone away