日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

VC++2010配置使用MySQL5.6

發(fā)布時間:2025/3/15 数据库 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC++2010配置使用MySQL5.6 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

?

0、前提

? ? 安裝后的文件概覽

? ??

?

?

? ? 編譯器: ?VC++2010

?

? ? MySQL版本:MySQL5.6.19 for win64?? ??

? ??

?

? ? Connector版本:connector ?c++ ?1.1.3

? ??

?

?

?

在VS2010下配置使用MySQL

?

1、配置頭文件

? ? 項目屬性--VC++目錄--包含目錄

? ??

?

?

2、配置庫文件

? ? 在connector c++ 1.1.3\lib目錄下有兩個目錄:debug目錄 和 opt目錄

? ??

?

?

? ? lib\debug目錄

? ??

?

?

?

? ? lib\opt目錄

? ??

?

? ? 由于有debug目錄,所以猜測opt目錄可能是類似release目錄的優(yōu)化(optimize)后的文件,因此在VC++中使用時在Debug下使用debug目錄下的庫文件,在Release模式下使用opt目錄下的庫目錄。

?

? ? eg.

? ? #ifdef ?_DEBUG

? ? #pragma ? comment(lib, "debug下的mysqlcppconn.lib")

? ? #pragma ? comment(lib, "debug下的mysqlcppconn-static.lib")

? ? #else?

? ? #pragma ? comment(lib, "opt下的mysqlcppconn.lib")

? ? #pragma ? comment(lib, "opt下的mysqlcppconn-static.lib")

? ? #endif

?

? ? 另外,在Debug或Release模式下將debug或opt目錄下的mysqlcppcon.dll拷貝到項目目錄下或system32目錄下。 ?將 MySQL\MySQL Server5.6\lib目錄下的libmysql.dll拷貝到項目目錄下或system32目錄下。

? ??

?

? ??

3、配置項目

? ? 由于該版本的MySQL是64位的,因此使用該MySQL的connector的項目必須被配置為X64類型的。 否則會有鏈接錯誤! 這一點要注意!

? ??

?

4、Demo

? ? 數(shù)據(jù)庫:db_1220, 表:tbl_user, ?MySQL服務器:本地的localhost

? ??

?

? ??

#include "stdafx.h" #include <Windows.h> #include <iostream> #include <mysql_connection.h> #include <cppconn/driver.h> #include <cppconn/exception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #pragma warning(disable:4251)#ifdef _DEBUG #pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\debug\\mysqlcppconn-static.lib") #pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\debug\\mysqlcppconn.lib") #else #pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\opt\\mysqlcppconn-static.lib") #pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\opt\\mysqlcppconn.lib") #endifusing namespace std;int _tmain(int argc, _TCHAR* argv[]) {sql::Driver *driver = NULL;sql::Connection *con = NULL;sql::Statement *stmt = NULL;sql::ResultSet *res = NULL;sql::SQLString strHost("localhost");sql::SQLString strUser("root");sql::SQLString strPwd("XXXXXXX");sql::SQLString strSchema("db_1220");sql::SQLString strQuery("select * from tbl_user");try{driver = get_driver_instance();con = driver->connect(strHost, strUser, strPwd);con->setSchema(strSchema);stmt = con->createStatement();res = stmt->executeQuery(strQuery);sql::ResultSetMetaData* pMetaData = res->getMetaData();cout << endl;cout << "Results have " << res->rowsCount() << " rows" << endl << endl;while(res->next()){//get data by column namecout << res->getInt("id")<< " "<< res->getString("name").c_str() //sql::SQLString沒有重載<<操作符,因此不能直接cout<<res->getString("name")<< " "<< res->getString("password").c_str()<< endl;//get data by column indexcout << res->getInt(1)<< " "<< res->getString(2).c_str()<< " "<< res->getString(3).c_str()<< endl;}}catch (sql::SQLException& e){cerr << endl << e.what() << endl;} catch (...){cerr << endl << "some exception happeded" << endl;}if (NULL != res)delete res;if (NULL != stmt)delete stmt;if (NULL != con)delete con;cout << endl << endl;return 0; }

?

? ??

?

運行結果:

?

?

?

?5、補充

? ? ?如果在編譯過程中報錯找不到類似 “<boost/variant.hpp>”這樣的錯誤信息,則是需要boost庫支持,下載boost庫配置一下即可。

??

? ??

?

轉載于:https://www.cnblogs.com/cuish/p/4175592.html

總結

以上是生活随笔為你收集整理的VC++2010配置使用MySQL5.6的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。