MySQL Connector 编程
MySQL Connector 是MySQL数据库客户端编程的接口, 它提供了通过网络访问数据库的接口, 这些功能在动态链接库(.dll, .so)或者静态对象库(.lib, .a)中实现.
使用时必须注意这些库是32位还是64位的.
下面是一个例子:
#include <stdio.h>
#include <stdlib.h>
#include <C:\Program Files\MySQL\MySQL Connector C 6.1\include\mysql.h> // 使用静态对象库
//#pragma comment(lib, "C:\\Program Files\\MySQL\\MySQL Connector C 6.1\\lib\\vs12\\mysqlclient.lib") // 使用动态链接库
// 确保 libmysql.dll 在系统路径中可以搜到
#pragma comment(lib, "C:\\Program Files\\MySQL\\MySQL Connector C 6.1\\lib\\libmysql.lib") void simpleUsega()
{
MYSQL *conn;
conn = mysql_init(NULL);
if (conn == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit();
}
if (mysql_real_connect(conn, "localhost", "user_name",
"user_password", NULL, , NULL, ) == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit();
}
if (mysql_query(conn, "create database frist_db")) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit();
}
mysql_close(conn); } int main() {
MYSQL *mysql = NULL;
char pwd[];
char usr[]; printf("Target platform word length : %d \n", sizeof(void*) );
printf("Connector version: %s \n", mysql_get_client_info()); //simpleUsage();
//return 0; printf("Initializing MySQL Connector... \n");
mysql_library_init(, NULL, NULL); // 在其他work线程产生之前初始化mysql c库, 不要让mysql_init来调用, 否则可能导致线程安全问题
if (!(mysql = mysql_init(NULL))) {
printf("Field. \n");
goto end;
} printf("OK, Conecting... \n"); // 配置用户和密码
if () {
printf("Please keyin user_name and password \n"
"name: ");
scanf_s("%s", usr, );
printf("pwd : ");
scanf_s("%s", pwd, );
} else {
sprintf_s(usr, , "default_user_name");
sprintf_s(pwd, , "default_user_password");
} // 连接 localhost 上的服务器
if (!mysql_real_connect(mysql, "localhost", usr, pwd, (const char*) , , NULL, )) {
printf("Filed, Error %u, %s \n", mysql_errno(mysql), mysql_error(mysql) );
goto end;
}
printf("Login succeed. \n"); // 销毁密码
sprintf_s(pwd, , "");
// 查询数据库服务器时间
mysql_query(mysql, "SELECT NOW();");
if (!mysql_errno(mysql)) {
MYSQL_RES *result;
MYSQL_ROW row;
int num_fields;
int i; result = mysql_store_result(mysql);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
for(i = ; i < num_fields; i++)
{
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");
}
mysql_free_result(result);
} end:
system("pause");
mysql_close(mysql);
mysql_library_end();
return 0;
}
MySQL Connector 编程的更多相关文章
- 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL
创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...
- [转]MySQL Connector/C++(一)
http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...
- python_基础学习_04_mysql库验证与安装(mysql-python,mysql.connector)
验证python-mysql是否安装 1:python 2: import MySQLdb 安装步骤: 1.sudo apt-get install python-setuptools 2.sudo ...
- MySQL Connector/J
5.1 Developer Guide 1. MysQL为由Java语言编程的客户端程序提供连接:MySQL Connector/J,这是一个实现Java Database Connectivity( ...
- MySql Connector/C++8简介
MySql Connector/C++8是一个用于连接MySQL服务器的C++应用程序.Connector/C++8可用于访问实现文档存储的 MySQL服务器,或者使用SQL查询以传统方式访问.它支持 ...
- vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...
- Using MySQL Connector .NET 6.6.4 with Entity Framework 5
I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new a ...
- mysql.connector操作mysql的blob值
This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...
- Ubuntu & MacOS安装Mysql & connector
Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...
随机推荐
- SpringBoot 从application.yml中通过@Value读取不到属性值
package cn.exrick.xboot.mqtt; import org.eclipse.paho.client.mqttv3.*;import org.eclipse.paho.client ...
- Hdoj 1160.FatMouse's Speed 题解
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- Poj 1659.Frogs' Neighborhood 题解
Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和 ...
- 【BZOJ3561】DZY Loves Math VI (数论)
[BZOJ3561]DZY Loves Math VI (数论) 题面 BZOJ 题解 \[\begin{aligned} ans&=\sum_{i=1}^n\sum_{j=1}^m\sum_ ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- 【UOJ#236】[IOI2016]railroad(欧拉回路,最小生成树)
[UOJ#236][IOI2016]railroad(欧拉回路,最小生成树) 题面 UOJ 题解 把速度看成点,给定的路段看成边,那么现在就有了若干边,然后现在要补上若干边,以及一条\([inf,\) ...
- squid详解(正向代理、透明代理、反向代理)
squid http://www.squid-cache.org/ --官方网址 squid软件主要有两大应用:1,代理上网(正向代理,透明代理) 2,网站静态页面缓存加速(反向代理) 三种代理类型: ...
- (1)Phonics自然拼读 英语动画 Fun with Phonics 国际主流英语教学法
Phonics(拼音英语)是目前国际主流的英语教学法,我国香港和台湾地区2000年就已引进此教学法,并已进入大规模推广和普及阶段.它之所以风靡全球,是因为这种教学法简单高效,符合人类学习语言的规律,尤 ...
- MySQL表结构的优化和设计
仅供自己学习 结论写在前面: 1.给字段选取最合适的数据类型 2.数据类型的宽度尽可能的小 3.给where条件的字段设置索引 4.允许部分数据冗余 5.字段要尽可能的设置为not null,特别 ...
- 逻辑回归 代价函数J关于系数theta求导
J=-y*loga-(1-y)*log(1-a) 梯度下降,求dJ/d_theta_j