Home > Database > Mysql Tutorial > body text

VisualStudio2013C++使用API连接MYSQL(64位)_MySQL

WBOY
Release: 2016-06-01 13:19:10
Original
1313 people have browsed it

bitsCN.com

环境:mysql5.6.12(x64) 、visual studio 2013

语言:C++

步骤:

1.创建win32应用程序

2.添加include目录(%MYSQL_HOME%/include)(注:%MYSQL_HOME%替换为你的mysql安装目录)

3.copy libmysql.lib和libmysql.dll到项目目录

4.创建文件source.cpp(注,请替换"***"为mysql登陆密码)

#include<winsock2.h>#include<mysql.h>#include<iostream>#pragma comment(lib,"libmysql.lib")int main(){	MYSQL mysql;	mysql_init(&mysql);	if (!mysql_real_connect(&mysql, "localhost", "root", "***", "test", 3306, NULL, 0))	{		std::cout << "数据库连接失败" << std::endl;	}	else	{		std::cout << "连接成功" << std::endl;	}	return 0;}
Copy after login
5.编译结果如下:

n块Н楗

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!