一、创建项目如下图:
二、配置编译器
1、工具—》选项
2、如图
3、如图:
3、项目附加配置
添加libmysql.lib mysqlclient.lib mysys.lib zlib.lib库文件,中间以空格隔开
三、内容
里面有注释,在这里不做解释!
#include "stdafx.h"
#include "winsock2.h"
#include <windows.h>
#include <iostream>
#include <mysql.h>
#include <stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
}
四、编译
按F7执行编译
1>------ Build started: Project: first_mysql, Configuration:
Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>first_mysql.cpp
1>Compiling manifest to resources...
1>Linking...
1>LINK : D:My DocumentsVisual Studio
2005Projectsfirst_mysqlDebugfirst_mysql.exe not found or not
built by the last incremental link; performing full link
1>Embedding manifest...
1>Build log was saved at "file://d:My DocumentsVisual Studio
2005Projectsfirst_mysqlfirst_mysqlDebugBuildLog.htm"
1>first_mysql - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
==========
五、程序运行结果
下面为mysql查询结果:
mysql> use my_database;
Database changed
mysql> select *
+-----+------+-------+----------+
| aid | id
+-----+------+-------+----------+
|
|
|
|
|
|
+-----+------+-------+----------+
6 rows in set (0.06 sec)
六、附件
1、my_table的数据结构
mysql> desc my_table;
+-------+--------------+------+-----+---------+----------------+
| Field |
Type
+-------+--------------+------+-----+---------+----------------+
| aid
| id
| first | varchar(100) | YES
| sec
+-------+--------------+------+-----+---------+----------------+
4 rows in set (0.08 sec)
2、创建表语句
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=gb2312
执行结构一致!示例程序成功!
如有不明之处,请留言共同商讨!