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 编程的更多相关文章

  1. 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL

    创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...

  2. [转]MySQL Connector/C++(一)

    http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...

  3. python_基础学习_04_mysql库验证与安装(mysql-python,mysql.connector)

    验证python-mysql是否安装 1:python 2: import MySQLdb 安装步骤: 1.sudo apt-get install python-setuptools 2.sudo ...

  4. MySQL Connector/J

    5.1 Developer Guide 1. MysQL为由Java语言编程的客户端程序提供连接:MySQL Connector/J,这是一个实现Java Database Connectivity( ...

  5. MySql Connector/C++8简介

    MySql Connector/C++8是一个用于连接MySQL服务器的C++应用程序.Connector/C++8可用于访问实现文档存储的 MySQL服务器,或者使用SQL查询以传统方式访问.它支持 ...

  6. vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错

    包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...

  7. 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 ...

  8. mysql.connector操作mysql的blob值

    This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...

  9. Ubuntu & MacOS安装Mysql & connector

    Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...

随机推荐

  1. linux添加lvm磁盘大小,命令行创建swap

    添加硬盘 添加一块硬盘. 重新扫描硬盘 echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -&quo ...

  2. CPU监控 解题报告

    CPU监控 这种题就需要小黄鸭调试法,不行就重构,动态gdb可能会死人,一堆tag的... 维护历史最值的一个核心是历史最值tag,它的意义是从上一次这个点下放tag之后到当前时刻的这个点的tag达到 ...

  3. 「JLOI2015」城池攻占 解题报告

    「JLOI2015」城池攻占 注意到任意两个人的战斗力相对大小的不变的 可以离线的把所有人赛到初始点的堆里 然后做启发式合并就可以了 Code: #include <cstdio> #in ...

  4. bzoj1066 蜥蜴 (dinic)

    最大流板子题. 对于每根柱子,建两个点ai,bi,建边(ai,bi,柱子高度) 对于距离不超过d的两根柱子i,j,建边(bi,aj,inf) 对于起始位置在i的每个蜥蜴,建边(S,ai,1) 对于能跳 ...

  5. [APIO2013]机器人(斯坦纳树)

    题目描述 VRI(Voltron 机器人学会)的工程师建造了 n 个机器人.任意两个兼容的机 器人站在同一个格子时可以合并为一个复合机器人. 我们把机器人用 1 至 n 编号(n ≤ 9).如果两个机 ...

  6. PyCharm创建自定义代码段(JetBrains系列通用)

    创建自定义代码段或者修改代码段:(用习惯了VSCode的main格式,固而改下)

  7. 详解vue的数据binding原理

    自从angular火了以后,各种mv*框架喷涌而出,angular虽然比较火,但是他的坑还是蛮多的,还有许多性能问题被人们吐槽.比如坑爹的脏检查机制,数据binding是受人喜爱的,脏检查就有点…性能 ...

  8. eureka集群基于DNS配置方式

    https://www.cnblogs.com/relinson/p/eureka_ha_use_dns.html   最近在研究spring cloud eureka集群配置的时候碰到问题:多台eu ...

  9. JAVA中循环删除list中元素

    文章来源: https://www.cnblogs.com/pcheng/p/5336903.html JAVA中循环遍历list有三种方式for循环.增强for循环(也就是常说的foreach循环) ...

  10. windows蜜汁调音

    哈,用的蜂鸣器,我静音了这东西还放. 只能调的很垃圾,但是很好玩. #include<cstdio> #include<windows.h> using namespace s ...