MySql 中文参考指南

Chapter 31 Connectors and APIs

目录

Table of Contents

MySQL Connectors 为客户端程序提供与 MySQL 服务器的连接。API 通过经典 MySQL 协议或 X 协议提供对 MySQL 资源的低级访问。无论采用哪种方法,Connectors 和 API 都使您能够通过其他语言或环境连接和执行 MySQL 语句,包括 ODBC、Java (JDBC)、C++、Python、Node.js、PHP、Perl、Ruby 和 C。

MySQL Connectors provide connectivity to the MySQL server for client programs. APIs provide low-level access to MySQL resources using either the classic MySQL protocol or X Protocol. Both Connectors and the APIs enable you to connect and execute MySQL statements from another language or environment, including ODBC, Java (JDBC), C++, Python, Node.js, PHP, Perl, Ruby, and C.

MySQL Connectors

Oracle 开发了许多连接器:

Oracle develops a number of connectors:

  1. Connector/C enables C applications to connect to MySQL.

  2. Connector/J provides driver support for connecting to MySQL from Java applications using the standard Java Database Connectivity (JDBC) API.

  3. Connector/NET enables developers to create .NET applications that connect to MySQL. Connector/NET implements a fully functional ADO.NET interface and provides support for use with ADO.NET aware tools. Applications that use Connector/NET can be written in any supported .NET language.

  4. Connector/ODBC provides driver support for connecting to MySQL using the Open Database Connectivity (ODBC) API. Support is available for ODBC connectivity from Windows, Unix, and macOS platforms.

  5. Connector/Python provides driver support for connecting to MySQL from Python applications using an API that is compliant with the Python DB API version 2.0. No additional Python modules or MySQL client libraries are required.

  6. Connector/Node.js provides an asynchronous API for connecting to MySQL from Node.js applications using X Protocol. Connector/Node.js supports managing database sessions and schemas, working with MySQL Document Store collections and using raw SQL statements.

The MySQL C API

为了直接在 C 应用程序中以本机方式使用 MySQL, C API 通过 libmysqlclient 客户端库提供低级访问权限来访问 MySQL 客户端/服务器协议。这是连接到 MySQL 服务器实例的主要方法,MySQL 命令行客户端以及此处详述的许多 MySQL 连接器和第三方 API 都使用此方法。

For direct access to using MySQL natively within a C application, the C API provides low-level access to the MySQL client/server protocol through the libmysqlclient client library. This is the primary method used to connect to an instance of the MySQL server, and is used both by MySQL command-line clients and many of the MySQL Connectors and third-party APIs detailed here.

libmysqlclient 包含在 MySQL 发行版中。

libmysqlclient is included in MySQL distributions distributions.

另请参阅 MySQL C API Implementations

要从 C 应用程序访问 MySQL,或为本章节中的连接器或 API 不支持的语言构建 MySQL 接口, C API 是起点。提供了一些编程工具来帮助完成此过程;请参见 Section 6.7, “Program Development Utilities”

To access MySQL from a C application, or to build an interface to MySQL for a language not supported by the Connectors or APIs in this chapter, the C API is where to start. A number of programmer’s utilities are available to help with the process; see Section 6.7, “Program Development Utilities”.

Third-Party MySQL APIs

本章中描述的其余 API 提供了从特定应用程序语言到 MySQL 的接口。这些第三方解决方案不是 Oracle 开发或支持的。仅出于引用目的,此处提供了关于其用法和功能的基本信息。

The remaining APIs described in this chapter provide an interface to MySQL from specific application languages. These third-party solutions are not developed or supported by Oracle. Basic information on their usage and abilities is provided here for reference purposes only.

所有第三方语言 API 都是使用_libmysqlclient_或通过实现本机驱动程序这两种方法之一开发的。这两种解决方案提供了不同的好处:

All the third-party language APIs are developed using one of two methods, using libmysqlclient or by implementing a native driver. The two solutions offer different benefits:

  1. Using libmysqlclient offers complete compatibility with MySQL because it uses the same libraries as the MySQL client applications. However, the feature set is limited to the implementation and interfaces exposed through libmysqlclient and the performance may be lower as data is copied between the native language, and the MySQL API components.

  2. Native drivers are an implementation of the MySQL network protocol entirely within the host language or environment. Native drivers are fast, as there is less copying of data between components, and they can offer advanced functionality not available through the standard MySQL API. Native drivers are also easier for end users to build and deploy because no copy of the MySQL client libraries is needed to build the native driver components.

Table 31.1, “MySQL APIs and Interfaces” 列出了可用于 MySQL 的许多库和接口。

Table 31.1, “MySQL APIs and Interfaces” lists many of the libraries and interfaces available for MySQL.

表 31.1 MySQL API 和接口

Table 31.1 MySQL APIs and Interfaces

Environment

API

Type

Notes

Ada

GNU Ada MySQL Bindings

libmysqlclient

See MySQL Bindings for GNU Ada

C

C API

libmysqlclient

See MySQL 9.0 C API Developer Guide.

C++

Connector/C++

libmysqlclient

See MySQL Connector/C++ 9.0 Developer Guide.

MySQL++

libmysqlclient

See MySQL website.

MySQL wrapped

libmysqlclient

See MySQL wrapped.

Cocoa

MySQL-Cocoa

libmysqlclient

Compatible with the Objective-C Cocoa environment. See http://mysql-cocoa.sourceforge.net/

D

MySQL for D

libmysqlclient

See MySQL for D.

Eiffel

Eiffel MySQL

libmysqlclient

See Section 31.13, “MySQL Eiffel Wrapper”.

Erlang

erlang-mysql-driver

libmysqlclient

See erlang-mysql-driver.

Haskell

Haskell MySQL Bindings

Native Driver

See Brian O’Sullivan’s pure Haskell MySQL bindings.

hsql-mysql

libmysqlclient

See MySQL driver for Haskell.

Java/JDBC

Connector/J

Native Driver

See MySQL Connector/J Developer Guide.

Kaya

MyDB

libmysqlclient

See MyDB.

Lua

LuaSQL

libmysqlclient

See LuaSQL.

.NET/Mono

Connector/NET

Native Driver

See MySQL Connector/NET Developer Guide.

Objective Caml

OBjective Caml MySQL Bindings

libmysqlclient

See MySQL Bindings for Objective Caml.

Octave

Database bindings for GNU Octave

libmysqlclient

See Database bindings for GNU Octave.

ODBC

Connector/ODBC

libmysqlclient

See MySQL Connector/ODBC Developer Guide.

Perl

DBI/DBD::mysql

libmysqlclient

See Section 31.9, “MySQL Perl API”.

Net::MySQL

Native Driver

See Net::MySQL at CPAN

PHP

mysql, ext/mysql interface (deprecated)

libmysqlclient

See MySQL and PHP.

mysqli, ext/mysqli interface

libmysqlclient

See MySQL and PHP.

PDO_MYSQL

libmysqlclient

See MySQL and PHP.

PDO mysqlnd

Native Driver

Python

Connector/Python

Native Driver

See MySQL Connector/Python Developer Guide.

Python

Connector/Python C Extension

libmysqlclient

See MySQL Connector/Python Developer Guide.

MySQLdb

libmysqlclient

See Section 31.10, “MySQL Python API”.

Ruby

mysql2

libmysqlclient

Uses libmysqlclient. See Section 31.11, “MySQL Ruby APIs”.

Scheme

Myscsh

libmysqlclient

See Myscsh.

SPL

sql_mysql

libmysqlclient

See sql_mysql for SPL.

Tcl

MySQLtcl

libmysqlclient

See Section 31.12, “MySQL Tcl API”.