设置Visual Studio 2019 连接MySQL
一、创建项目并运行
1、新建一个空项目
2、添加源文件,书写代码
//部分代码,最终代码在后面
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL conn;
MYSQL_RES* result;
MYSQL_ROW sql_row;
const char* username = "xxx"; //username
const char* passwd = "xxx"; //password
const char* host = "localhost"; //or"127.0.0.1"
const char* database = "xxx"; //database
unsigned int port = 3306; //server port
int res;
mysql_init(&conn); //初始化一个MYSQL 连接的实例对象
//...省略中间代码
mysql_close(&conn);//断开连接,释放一个MYSQL 连接实例
return 0;
}
3、试运行,会报错
报错提示:fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory