mysql.h的报错还没有解决,你们不用看了,等我解决了吧还不知道什么时候

先用c吧

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h> MYSQL *g_conn; // mysql 连接
MYSQL_RES *g_res; // mysql 记录集
MYSQL_ROW g_row; // 字符串数组,mysql 记录行 #define MAX_BUF_SIZE 1024 // 缓冲区最大字节数 const char *g_host_name = "localhost";
const char *g_user_name = "root";
const char *g_password = "python123";
const char *g_db_name = "c_test";
const unsigned int g_db_port = ; void print_mysql_error(const char *msg) // 打印最后一次错误
{
if (msg)
printf("%s: %s\n", msg, mysql_error(g_conn));
else
puts(mysql_error(g_conn));
} int executesql(const char * sql)
{
/*query the database according the sql*/
if (mysql_real_query(g_conn, sql, strlen(sql))) // 如果失败
return -; // 表示失败 return ; // 成功执行
} int init_mysql() // 初始化连接
{
// init the database connection
g_conn = mysql_init(NULL); /* connect the database */
if(!mysql_real_connect(g_conn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, )) // 如果失败
return -; // 是否连接已经可用
executesql("set names utf8"); // 如果失败
// return -1;
return ; // 返回成功
} int main(void)
{
if (init_mysql());
print_mysql_error(NULL); char sql[MAX_BUF_SIZE]; if (executesql("select * from user")) // 句末没有分号
print_mysql_error(NULL); g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集 int iNum_rows = mysql_num_rows(g_res); // 得到记录的行数
int iNum_fields = mysql_num_fields(g_res); // 得到记录的列数 printf("共%d个记录,每个记录%d字段\n", iNum_rows, iNum_fields); puts("id\tname\n"); while ((g_row=mysql_fetch_row(g_res))) // 打印结果集
printf("%s\t%s\n", g_row[], g_row[]); // 第一,第二字段 mysql_free_result(g_res); // 释放结果集 mysql_close(g_conn); // 关闭链接 return EXIT_SUCCESS;
}

g++ -g -o mysql -I /usr/include/mysql main.cpp -L /usr/lib/x86_64-linux-gnu/ -lmysqlclient -lz -lpthread

1.介绍需求:

  python调用数据库,并做逻辑处理,时间为92.5s,从执行sql到得到数据150w条为22s,逻辑处理(2个for循环)为60s。前端处理30s,pending为2min左右,需要处理这个问题

  于是思考解决方案:  

    1. 取数据时数据拆分  

       先一个count返回条目,然后多次查询
    2. 逻辑部分怎么办?
      我想用c++处理试试,于是找代码,打算用python调用c++处理试试
      示例:
      

#include <iostream>
#include <string>
#include <cstdlib> #include <mysql++/mysql++.h> using namespace std; #define MYSQL_USER "root"
#define MYSQL_PASSWD "passwd"
#define MYSQL_PORT 3306 int main(){ mysqlpp::Connection con(false);
con.set_option(new mysqlpp::SetCharsetNameOption("utf8"));
if(!con.connect("test","localhost",MYSQL_USER,MYSQL_PASSWD,MYSQL_PORT)){
cout<<"can't connect,check the user and passwd"<<endl;
return -;
}
cout<<"mysql connect successfully!"<<endl; mysqlpp::Query query=con.query("select * from City");
mysqlpp::StoreQueryResult result=query.store();
if(nullptr==result){
cout<<"query failed!"<<endl;
return -;
} for(auto iter=result.begin();iter!=result.end();++iter){
cout<<"\t"<<(*iter)[]<<endl;
} return ;
}

报错:

/opt/code/testC++/tcp_server/test_server_1/main.cpp::: fatal error: mysql++/mysql++.h: 没有那个文件或目录
#include <mysql++/mysql++.h>

2. 怎么安装<mysql++/mysql++.h>头文件

系统环境:

  debian系统kali

1. 配置

debian: 
  apt-get install libmysqlclient-dev libmysql++-dev
redhat:
  yum install mysql-devel

发现没有,就这么干,根据不同系统因地制宜

apt-cache search libmysql
发现没有
apt-get update更新源
apt-cache search libmysql 有了类似的了
apt-get install default-libmysqlclient-dev default-libmysqld-dev

2. 下载解压安装:

[root@localhost 下载]#wget https://tangentsoft.com/mysqlpp/releases/mysql++-3.2.4.tar.gz
[root@localhost 下载]# tar zxvf mysql++-3.2..tar.gz

进入mysql++目录下,开始编译,先执行./configure生成makefile文件,之后再make,编译出libmysqlpp.so库文件:

./configure

报错:

下面这段来自blog:https://blog.csdn.net/daodaozhu05/article/details/12970657

checking for MySQL include directory... configure: error: Didn't find the MySQL include dir in '
/usr/include/mysql
/usr/local/include/mysql
/usr/local/mysql/include
/usr/local/mysql/include/mysql
/usr/mysql/include/mysql
/opt/mysql/include/mysql
/sw/include/mysql'

这个有两种情况,这个是第一种

首先查找本地libmysqlclient的目录在哪里,在终端敲下面的命令:

locate libmysqlclient
sudo ./configure --with-mysql-lib=/usr/lib/x86_64-linux-gnu

如果还出现刚才的问题

Didn't find the mysql in ......

这是用--with-mysql-include选项进行安装,比如我的mysqlclient lib在/opt/local/lib/mysql5/mysql, 而mysql 在/opt/local/include/mysql5/mysql,则用下列命令安装一遍即可。

sudo ./configure --with-mysql-lib=/opt/local/lib/mysql5/mysql/ --with-mysql-include=/opt/local/include/mysql5/mysql/

3.编译并安装

sudo make

sudo make install

第二种方法:

apt-cache search libmysql
发现没有
apt-get update更新源
apt-cache search libmysql 有了类似的了

apt-get install default-libmysqlclient-dev default-libmysqld-dev
 
root@corleone:/usr/local/lib# apt-cache search libmysql
default-libmysqlclient-dev - MySQL database development files (metapackage)
default-libmysqld-dev - MySQL embedded database development files (metapackage)
libcrypt-mysql-perl - Perl module to emulate the MySQL PASSWORD() function
libglpk40 - linear programming kit with integer (MIP) support
libmariadbclient-dev-compat - MariaDB database development files (libmysqlclient compatibility)
libmysql-diff-perl - module for comparing the table structure of two MySQL databases
libmysql-ocaml - OCaml bindings for MySql (runtime package)
libmysql-ocaml-dev - OCaml bindings for MySql (development package)
libmysqlcppconn-dev - MySQL Connector for C++ (development files)
libmysqlcppconn7v5 - MySQL Connector for C++ (library)
libreoffice-base-drivers - Database connectivity drivers for LibreOffice
node-mysql - MySQL client implementation for Node.js
solr-common - Enterprise search server based on Lucene3 - common files

然后直接也OK

./configure
 make 

 make install

4. 添加软连接

此段来自blog:https://www.cnblogs.com/zhxilin/p/5897211.html

install成功后会将.so文件拷贝到/usr/local/lib下,并把.h头文件拷贝到/usr/local/include下。

到这里MySQL++已经安装到本机了,然而如果直接在C++代码里引用如下头文件是无法编译通过的!

#include <mysql++.h>

原因是C++在编译时需要加载这个动态库,默认情况下,g++编译器只会使用/lib和/usr/lib这两个目录下的库文件。

回头看一下make之前的./configure步骤,我们并没有指定--prefix=/some/path,所以库会默认安装到/usr/local目录下。

既然libmysqlpp.so是在/usr/local/lib下,编译器当然就无法找到它的定义了。

那么编译器如何正确找到/usr/local/lib目录呢?

/etc/ld.so.conf文件记录了编译器编译时使用的动态库路径!那我们把/usr/local/lib路径加入到文件末尾就可以了!

次配置文件修改保存后,通过ldconfig程序(在usr/sbin/下),将/etc/ld.so.conf文件列举的路径下的库文件缓存到/etc/ld.so.cache以供开发使用

[root@localhost mysql++]# ldconfig

然后

[root@localhost mysql++]# ln -s /usr/local/lib/libmysqlpp.so /usr/lib/libmysqlpp.so

然并卵;;;

/usr/local/include/mysql++/common.h:219:11: fatal error: mysql.h: 没有那个文件或目录
# include <mysql.h>
^~~~~~~~~

  

3.执行c++代码执行测试

#include <mysql++/mysql++.h>

int main()

{

  cout << "hello world" << endl;return ;

}

g++ test.cpp -o test.so

./test.so

这里还有可能报错,为什么,有可能是你用的编译器的问题,举个例子,你用的是clion软件,而这个软件默认是cmake的所以我们需要手动编译

指定一些东西 :https://www.cnblogs.com/lywy510/p/3615710.html

g++ -g -o mysql.so -I /usr/include/mysql test.cpp -L /usr/lib/x86_64-linux-gnu/ -lmysqlclient -lz

如果是c的话,就是gcc喽

编译的时候要注意用到2个路径,mysql.h和libmysqlclient.so的路径

查找mysql.h路径

[root@liu mysql]# find / -name 'mysql.h'
/usr/include/mysql/mysql.h
[root@liu mysql]# find / -name '*mysqlclient*'

/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient.a
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.a
/usr/lib/x86_64-linux-gnu/libmysqlclient.so
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18.0.0
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18

然后./mysql.so,就可以啦

debian系列下c++调用mysql, linux下面安装mysql.h文件的更多相关文章

  1. Linux中安装MySQL

    因为使用yum安装.安装过程需保证网络通畅 一.安装mysql 1.yum安装mysqlCentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源 ...

  2. 怎样在 Ubuntu Linux 上安装 MySQL

    本教程教你如何在基于 Ubuntu 的 Linux 发行版上安装 MySQL.对于首次使用的用户,你将会学习到如何验证你的安装和第一次怎样去连接 MySQL. -- Sergiu MySQL 是一个典 ...

  3. linux上安装 mysql

    一.linux 上安装 mysql 1.查看mysql是否安装 rpm -qa|grep mysql 2.卸载 mysql yum remove mysql mysql-server mysql-li ...

  4. Linux 上安装 mysql

    1.通过 yum 命令安装 mysql 可以先通过 yum list |grep mysql 方式查看有哪些版本的 mysql 2.安装 mysql yum install mysql-server ...

  5. MySQL介绍及安装&MySQL软件基本管理

    mysql介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好 ...

  6. 记录下在阿里云linux上安装与配置Mysql

    环境:阿里云ECS服务器,系统为centos7.2 用户:root 参考博客:https://blog.csdn.net/kunzai6/article/details/81938613 师兄的哈哈哈 ...

  7. linux(Centos7)安装mysql

    查看系统环境 [root@localhost html]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) CentOS 7 ...

  8. linux上安装mysql

    linux下mysql 最新版安装图解教程 1.查看当前安装的linux版本 命令:lsb_release -a 如下图所示 通过上图中的数据可以看出安装的版本为RedHat5.4,所以我们需要下载R ...

  9. 亲测linux上安装mysql

    1.rpm -ivh MySQL-server-5.6.19-linux_glibc2.5.x86_64.rpm(这是复制过来的,用Tab键自动补齐吧)2.rpm -ivh MySQL-client- ...

随机推荐

  1. BZOJ.5120.[清华集训2017]无限之环(费用流zkw 黑白染色)

    题目链接 LOJ 洛谷 容易想到最小费用最大流分配度数. 因为水管形态固定,每个点还是要拆成4个点,分别当前格子表示向上右下左方向. 然后能比较容易地得到每种状态向其它状态转移的费用(比如原向上的可以 ...

  2. BZOJ.3757.苹果树(树上莫队)

    题面链接 /* 代码正确性不保证..(不过交了SPOJ没WA T了最后一个点) 在DFS序做莫队 当一个点不是另一个点的LCA时,需要加上它们LCA的贡献 */ #include <cmath& ...

  3. Python3练习题系列(10)——项目骨架构建

    目标: 如何创建<项目“骨架”目录> 包含:项目文件布局.自动化测试代码,模组,以及安装脚本. 由于编写一个Python文件可以作为一个模块,一个带__init__.py的目录算一个包. ...

  4. 自动部署tomcat 脚本

    自动部署tomcat 脚本 . /etc/init.d/functions #调用系统函数 yum -y install java >/dev/null TAR="apache-tom ...

  5. 迭代函数:zip、enumerate,list解析

    #encoding:utf-8 """ 并行迭代: zip enumerate 获取元素及下标 list解析 iter """ #zip # ...

  6. How to modify analog output range of Arduino Due

    Voltage Translation for Analog to Digital Interface ADC How to modify analog output range of Arduino ...

  7. [CGAL]带岛多边形三角化

    CGAL带岛多边形三角化,并输出(*.ply)格式的模型 模型输出的关键是节点和索引 #include <CGAL/Triangulation_vertex_base_with_id_2.h&g ...

  8. 矩阵乘法code

    VOJ1067 我们可以用上面的方法二分求出任何一个线性递推式的第n项,其对应矩阵的构造方法为:在右上角的(n-1)*(n-1)的小矩阵中的主对角线上填1,矩阵第n行填对应的系数,其它地方都填0.例如 ...

  9. Spark机器学习(8):LDA主题模型算法

    1. LDA基础知识 LDA(Latent Dirichlet Allocation)是一种主题模型.LDA一个三层贝叶斯概率模型,包含词.主题和文档三层结构. LDA是一个生成模型,可以用来生成一篇 ...

  10. 基于SIFT特征的全景图像拼接

    基于SIFT特征的全景图像拼接 分类: image Machine learning2013-07-05 13:33 2554人阅读 评论(3) 收藏 举报 基于SIFT特征的全景图像拼接 分类: 计 ...