天天看點

【原創】modb 功能設計之“支援部分MySQL用戶端協定”-2

首先看看有哪些資源:

connector/c (libmysqlclient) is a client library for c development.

===

      mysql connector/c 是一個用戶端庫,提供了用于用戶端/伺服器通信的 c api 。其可作為單獨元件替代 mysql server 釋出版本中帶有的 mysql 用戶端庫。

使用 mysql connector/c 的理由:

如果你僅需要使用用戶端庫提供的功能,mysql connector/c 提供了你所需的一切。沒有必要源碼編譯或安裝 mysql server 包來擷取相關功能。

mysql connector/c 不依賴 mysql server 的釋出周期。bug 修複和新特特性添加均可獨立于 mysql server 的釋出。

目前存在如下 mysql connector/c 版本:

mysql connector/c 6.1:基于目前(5.6)mysql 源碼中的 c api 部分生成,并且與 5.6 源碼保持同步更新。

mysql connector/c 6.0:最初從 mysql 的源碼樹分支上建立,但目前相較于那條源碼樹分支上的 c api 内容已經過時。

結論就是,mysql connector/c 6.1 當然優于 6.0 。mysql connector/c 6.1 已提供了如下 6.0 中不具備的功能特性:

支援可插拔鑒權架構,即可以插件形式支援各種鑒權方法。該架構既可被用作 mysql 本地鑒權方式,又可用作外部鑒權方式。

支援用戶端側 sha-256,pam 和 windows 本地鑒權插件。老的 connector/c 6.0 僅能使用本地 mysql 密碼形式的賬号資訊來進行連接配接。如果用戶端想要使用一種不同的鑒權方式的賬戶資訊來進行連接配接,則會受到“目前使用者通路被拒絕”的錯誤。

支援 prepared call 語句,該功能使得用戶端程式,能夠在存儲過程中處理,産生的多結果集,并獲得最終的 out 和 inout 存儲過程參數值。

支援 ipv6 連接配接。

支援在連接配接時,将用戶端程式與指定 ip 位址進行綁定。

支援在連接配接時,指定連接配接屬性來告之伺服器端。

下表中給出了 mysql connector/c 已經測試過的平台。

table 22.28. supported platforms for mysql connector/c 6.1

platform

versions

windows

windows vista, server 2008, server 2012, 7, 8

linux

oracle and rhel 5, 6; suse les 11; centos 5, 6; fedora 15, 16; opensuse 12.1; debian 6; ubuntu 12.04; generic glibc 2.5-based linux systems

solaris

10, 11

mac os x

10.6, 10.7

freebsd

9

table 22.29. supported platforms for mysql connector/c 6.0.2

windows 2000, xp, vista, server 2003, server 2008

rhel 4, 5; suse les 9, 10; generic glibc 2-based linux systems

8, 9, 10

10.4, 10.5

6, 7

hp-ux

11.11, 11.23, 11.31

ibm aix    

5.3

mysql connector/c 6.1 distributions contain the header, library, and utility files necessary to build mysql client applications that communicate with mysql server using the c api.

distributions are available in binary and source formats. a binary distribution contains the header, library, and utility components discussed following, compiled and ready for use in writing client programs. a source distribution contains the source files required to produce the same headers, libraries, and utilities included in a binary distribution, but you compile them yourself.

mysql connector/c 分布包中包含如下元件:

a set of .h header files that c applications include at compile time. these files are located in the include directory.

static and dynamic libraries that c applications link to at link time. these libraries are located in the lib directory. the library names depend on the library type and platform for which a distribution is built:

unix(以及 unix-like)平台上,靜态庫為 libmysqlclient.a ,動态庫為 libmysqlclient.so 。

windows 平台上,靜态庫為 mysqlclient.lib ,動态庫為 libmysql.dll 。動态庫對應的靜态導入庫為 libmysql.lib 。相應 debug 版本的庫在 lib/debug 目錄下可以找到。

一些小實用程式。

【22.8.4.1. building c api client programs】

編譯 ms windows 上的 mysql 用戶端程式

指定頭檔案和庫檔案所在位置。

需要額外連結庫:ws2_32 和 secur32 。

需要連結靜态庫(mysqlclient.lib)或者動态庫(libmysql.dll)。

連結靜态庫時,需要注意:

用戶端應用程式必須使用,與庫編譯時相同的 vs 版本進行編譯。

用戶端應用程式應該使用編譯選項 /mt 來靜态連結 c 運作時庫。

      如果用戶端應用程式以 debug 模式建構,并且使用了靜态 debug c 運作時庫(編譯選項為 /mtd ),其可以連結到靜态庫 mysqlclient.lib ,當且僅當庫是采用同樣的編譯選項編譯時。如果用戶端應用程式使用動态 c 運作時庫(編譯選項為 /md 或者 debug 模式的 /mdd),則必須連結到 libmysql.dll 動态庫上,此時不可連結到靜态庫上。

添加或者改變的功能:

      專門針對 windows xp 和 windows server 2003 的條件變量實作已從源碼中移除,因為 mysql 5.6 決定不在提供上述平台的支援。

注意:上述該表應該做如下了解:connector/c 6.1 盡管在之前沒有被官方聲明支援 windows xp 或 windows server 2003,但是确實在上述平台是可用的。但從 6.1.2 版本開始已經不行了。

mysql 現已支援協定跟蹤插件的使用。

      通過 vs2008、vs2010、vs2012 生成的靜态庫現已作為 windows 平台 connector/c 包的一部分一同釋出。在 lib 目錄下的 vs9、vs10 和 vs11 分别包含了使用 vs2008、vs2010、vs2012 建構的靜态庫和相應的 pdb 檔案。

繼續閱讀