Visual studio C++连接到MYSQL服务器
Visual studio C++ connect to MYSQL server
当T试图运行我的c++程序连接到MYSQL服务器时,我遇到了错误。这是我的密码。
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/opencv.hpp"
#include <cmath>
#include <iostream>
#include "my_global.h"
#include "mysql.h"
int main() {MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "server";
char *user = "user";
char *password = "password"; // got tot keep my data secret
char *database = "cpp_test";
conn = mysql_init(NULL);
// connect to database
if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%sn", mysql_error(conn));
return -1;
}
// send SQL query
if(mysql_query(conn, "select * from cpp_testTAB"))
{
fprintf(stderr, "%sn", mysql_error(conn));
return -1;
}
res = mysql_use_result(conn);
// output table name
printf("MySQL Tables in mysql database:n");
while ((row = mysql_fetch_row(res)) != NULL)
{
printf("%s %s %s %sn", row[0], row[1], row[2], row[3]);
}
// close connection
mysql_free_result(res);
mysql_close(conn);
return 0;
}
这是我的附加包含目录
C:Program Files (x86)MySQLMySQL Server 5.6include
C:Program Files (x86)MySQLConnector.C++ 1.1include
附加库目录
C:Program Files (x86)MySQLMySQL Server 5.6lib
C:Program Files (x86)MySQLConnector.C++ 1.1libopt
附加依赖项
libmysql.lib
mysqlcppconn-static.lib
当我尝试运行程序时,出现了一些错误。
Error 1 error LNK2019: unresolved external symbol mysql_close referenced in function main
Error 2 error LNK2019: unresolved external symbol mysql_free_result referenced in function main
Error 3 error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main
Error 4 error LNK2019: unresolved external symbol mysql_use_result referenced in function main
Error 5 error LNK2019: unresolved external symbol mysql_query referenced in function main
Error 6 error LNK2019: unresolved external symbol mysql_error referenced in function main
Error 7 error LNK2019: unresolved external symbol mysql_real_connect referenced in function main
Error 8 error LNK2019: unresolved external symbol mysql_init referenced in function main
Error 9 error LNK1120: 8 unresolved externals C:UsersLahirudocumentsvisual studio 2010ProjectsLevel4-Projectx64DebugLevel4-Project.exe
我无法解决这个问题。如果有人能向我展示错误或示例教程链接,那就太好了。
问题似乎是您正在构建一个64位应用程序,但提供了32位库。给人这种印象的是这两条线:
Error 9 error LNK1120: 8 unresolved externals
C:UsersLahirudocumentsvisual studio 2010ProjectsLevel4-Projectx64DebugLevel4-Project.exe
这个:
C:Program Files (x86)MySQLMySQL Server 5.6lib
第一行的路径中有x64
,但第二行表明,由于Program Files (x86)
路径,您要查找的库是32位版本。
因此,请确保将64位库与64位应用程序链接,或者将应用程序更改为32位并与32位库链接。
相关文章:
- 在 MySQL 中运行 HTTP 服务器以从客户端接收数据
- mysql c ++连接器异常:用户"root"@'localhost'的访问被拒绝(使用密码:NO)&&MySQL服务器已消失
- 无法使用 mysql_real_connect() 连接到 mysql 服务器
- MySQL Windows c api 命名管道错误:"在'等待初始通信数据包'时丢失与 MySQL 服务器的连接,系统错误:0
- MySQL 服务器不接受远程连接
- MySQL服务器安装缺少libmysql.lib
- MySQL 服务器端超时
- 如何在Linux上使用Qt5访问远程MySQL服务器
- 如何从C#/C++应用程序连接到MySQL服务器
- Cocos2dx C++将游戏数据发送到远程服务器上的MySQL数据库
- 如何在Qt应用程序中连接到MySQL服务器
- 从远程 MySQL 服务器本地导出.csv数据
- 游戏服务器的C++MySQL
- Visual studio C++连接到MYSQL服务器
- c++程序退出段错误,查询时与MySQL服务器失去连接
- 我可以使用mysql_real_connect连接到服务器而不提及使用mysql/C的数据库吗
- 检测服务器过载以限制mysql查询
- Django作为mysql代理服务器
- MySQL客户端库与服务器的版本兼容性
- C++应用程序如何在不让MySQL服务器接受远程连接的情况下访问远程MySQL数据库