ubuntu下c++使用mysqlconnector连接mysql数据库
来源:互联网 发布:印度 种姓 知乎 编辑:程序博客网 时间:2024/06/05 11:43
1、安装mysqlconnector
sudo apt-get install libmysqlcppconn-dev
2、安装mysql
sudo apt-get install mysql-server
使用网上广泛引用的一个测试代码
#include <iostream>#include <sstream>#include <memory>#include <string>#include <stdexcept>using namespace std;#include <mysql_connection.h>#include <mysql_driver.h>#include <cppconn/driver.h>using namespace sql;#define DBHOST "tcp://127.0.0.1:3306"#define USER "root"#define PASSWORD "your password here"int main() { Driver *driver; Connection *conn; driver = get_driver_instance(); conn = driver->connect(DBHOST, USER, PASSWORD); conn->setAutoCommit(0); cout<<"DataBase connection autocommit mode = "<<conn->getAutoCommit()<<endl; delete conn; driver = NULL; conn = NULL; return 0;}
使用g++ -o testmysql testmysql.cpp -lmysqlcppconn 编译文件,运行即可
一定注意不要写成g++ -o testmysql -lmysqlcppconn testmysql.cpp 网上好多写这样的,让我查了半天也没找出哪错了。。。这样编译不通过
- ubuntu下c++使用mysqlconnector连接mysql数据库
- 使用MySQLConnector/C++连接MySQL数据库
- Ubuntu 10.04 下 C 连接mysql数据库
- Ubuntu下C连接mysql数据库
- Ubuntu 下使用Qt连接MySQL数据库
- ubuntu c++下连接mysql数据库和数据库的使用
- ubuntu c++下连接mysql数据库和数据库的使用
- ubuntu下使用Python连接Mysql数据库和Mongodb数据库
- linux ubuntu下C语言与数据库mysql连接
- ubuntu linux 下使用Qt连接MySQL数据库
- Linux 环境下使用 C API 连接 MYSQL 数据库
- Ubuntu下MySQL数据库使用
- Ubuntu QT C连接mysql数据库
- 远程连接ubuntu下mysql数据库
- Ubuntu下Tomcat连接MySql数据库
- ubuntu下mysql不能远程连接数据库
- ubuntu下mysql不能远程连接数据库
- Ubuntu下允许远程连接MySQL数据库
- VMware Station 安装Ubuntu 13.04 后进入系统出现问题
- 操作系统、网络重要知识点
- 黑马程序员_二十五 【银行业务调度系统】
- 对邮箱地址的校验和获取文字里的邮箱地址
- C/C++/Objective-C 日志记录功能模块
- ubuntu下c++使用mysqlconnector连接mysql数据库
- error C2264函数定义或声明中有错误;未调用函数
- Chrome错误 312 (net::ERR_UNSAFE_PORT):未知错误
- java动态代理原理(Proxy,InvocationHandler),含$Proxy0源码
- Linux一些重要的头文件
- HDU 1520 Anniversary party
- HDU 1069 Monkey and Banana
- U-Boot启动过程完全分析
- 我的架构经验小结(一)-- 常用的架构模型