想连上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); }
{ 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); }
解决方案 »
- MySQL定时操作
- MY SQL存储过程需要判断 NULL的问题
- MySQL Proxy是做分布式数据库用的吗?
- mysql表中增加/删除记录后,对应的索引需不需要重建?
- 求助:如何用sql语句取出mysql 数据库中表的字段的说明信息 !!!
- MYSQL4.1.8-win的服务器应该安装MYSQL-Front的哪些版本可以正常使用?
- mysql在企业中能否担当象SQL-SERVER这样的角色?
- 请教在WindowsXP下安装PostgreSQL的问题!!
- 怎样给表重命名?
- sql 查询语句 如果字段不存在 怎么使得还能正常查询
- mysql text格式 怎么substring()?
- mysql用户@'%'不能 登陆问题的问题
#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
1
MySQL server has gone away mysql> select * from reads_info;
Empty set (0.00 sec)mysql>
C++是想 把 data file load 到 reads_info表中, 但是不成功!
{ 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
1
MySQL server has gone away
查下原因吧,和load data 没有关系
cout < <mysql_error(&mysql) < <"\n";
对应输出1
MySQL server has gone away