- 31.1 MySQL 连接器/C++31.1 MySQL Connector/C++
- 31.2 MySQL 连接器/J31.2 MySQL Connector/J
- 31.3 MySQL 连接器/NET31.3 MySQL Connector/NET
- 31.4 MySQL 连接器/ODBC31.4 MySQL Connector/ODBC
- 31.5 MySQL 连接器/Python31.5 MySQL Connector/Python
- 31.6 MySQL 连接器/Node.js31.6 MySQL Connector/Node.js
- 31.7 MySQL C API
- 31.8 MySQL PHP API
- 31.9 MySQL Perl API
- 31.10 MySQL Python API
- 31.11 MySQL Ruby APIs
- 31.12 MySQL Tcl API
- 31.13 MySQL Eiffel 封装31.13 MySQL Eiffel Wrapper
MySQL 连接器为客户端程序提供与 MySQL 服务器的连接。API 使用经典 MySQL 协议或 X 协议提供对 MySQL 资源的低级访问。连接器和 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 连接器MySQL Connectors
Oracle 开发了多种连接器:Oracle develops a number of connectors:
Connector/C++ 使 C++ 应用程序能够连接 MySQL。Connector/C++ enables C++ applications to connect to MySQL.
Connector/J 提供驱动程序支持,使 Java 应用程序可以通过标准的 Java 数据库连接 (JDBC) API 连接到 MySQL。Connector/J provides driver support for connecting to MySQL from Java applications using the standard Java Database Connectivity (JDBC) API.
Connector/NET 使开发人员能够创建连接到 MySQL 的 .NET 应用程序。Connector/NET 实现了完整功能的 ADO.NET 接口,并为 ADO.NET 感知工具的使用提供支持。使用 Connector/NET 的应用程序可以用任何支持的 .NET 语言编写。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.
Connector/ODBC 提供驱动程序支持,使通过开放数据库连接 (ODBC) API 连接到 MySQL 成为可能。Windows、Unix 和 macOS 平台均提供 ODBC 连接支持。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.
Connector/Python 提供驱动支持,使 Python 应用程序能够使用符合 Python DB API 版本 2.0 的 API 连接到 MySQL。无需额外的 Python 模块或 MySQL 客户端库。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.
Connector/Node.js提供用于从 Node.js 应用程序通过 X 协议连接 MySQL 的异步 API。Connector/Node.js 支持管理数据库会话和模式、处理 MySQL 文档存储集合以及使用原生 SQL 语句。Connector/Node.jsprovides 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 实现,该 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 实现。See also MySQL C API Implementations.
要从 C 应用程序访问 MySQL,或者为本章中未支持的语言构建 MySQL 接口,可以从C API开始。有许多程序员工具可以帮助完成此过程;请参见第 6.7 节,“程序开发工具”。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”.
第三方 MySQL APIThird-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:
使用
libmysqlclient可以实现与 MySQL 的完全兼容,因为它使用与 MySQL 客户端应用程序相同的库。然而,其功能集仅限于通过libmysqlclient暴露的实现和接口,而且由于数据在本地语言和 MySQL API 组件之间被复制,性能可能较低。Usinglibmysqlclientoffers 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 throughlibmysqlclientand the performance may be lower as data is copied between the native language, and the MySQL API components.本地驱动程序 是在宿主语言或环境中完全实现的 MySQL 网络协议。本地驱动程序运行速度快,因为组件之间的数据复制较少,而且它们可以提供通过标准 MySQL API 无法获得的高级功能。对于最终用户来说,本地驱动程序也更容易构建和部署,因为构建本地驱动程序组件时不需要 MySQL 客户端库的副本。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.
表 31.1,“MySQL API 和接口” 列出了许多可用于 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 绑定GNU Ada MySQL Bindings | libmysqlclient |
请参见 GNU Ada 的 MySQL 绑定See MySQL Bindings for GNU Ada |
| CC | C API | libmysqlclient |
请参见 MySQL 8.4 C API 开发者指南。See MySQL 8.4 C API Developer Guide. |
| C++ | 连接器/CConnector/C++ | libmysqlclient |
请参见 MySQL Connector/C 9.5 开发者指南。See MySQL Connector/C++ 9.5 Developer Guide. |
| MySQL++ | libmysqlclient |
请参见 MySQL 网站。See MySQL++ website. | |
| 封装的 MySQLMySQL wrapped | libmysqlclient |
请参见 封装的 MySQL。See MySQL wrapped. | |
| Cocoa | MySQL-Cocoa | libmysqlclient |
兼容 Objective-C Cocoa 环境。请参见 http://mysql-cocoa.sourceforge.net/Compatible with the Objective-C Cocoa environment. See http://mysql-cocoa.sourceforge.net/ |
| DD | MySQL for D | libmysqlclient |
参见 D 语言的 MySQL。See MySQL for D. |
| Eiffel | Eiffel MySQL | libmysqlclient |
参见 第 31.13 节,“MySQL Eiffel 封装”。See Section 31.13, “MySQL Eiffel Wrapper”. |
| Erlang | erlang-mysql-driver |
libmysqlclient |
参见 erlang-mysql-driver。See
erlang-mysql-driver. |
| Haskell | Haskell MySQL 绑定Haskell MySQL Bindings | 原生驱动Native Driver | 参见 Brian O'Sullivan 的纯 Haskell MySQL 绑定。See Brian O'Sullivan's pure Haskell MySQL bindings. |
hsql-mysql |
libmysqlclient |
参见 Haskell 的 MySQL 驱动。See MySQL driver for Haskell. | |
| Java/JDBC | Connector/J | 原生驱动Native Driver | 参见 MySQL Connector/J 开发者指南。See MySQL Connector/J Developer Guide. |
| Kaya | MyDB | libmysqlclient |
参见 MyDB。See MyDB. |
| Lua | LuaSQL | libmysqlclient |
参见 LuaSQL。See LuaSQL. |
| .NET/Mono | Connector/NET | 原生驱动Native Driver | 参见 MySQL Connector/NET 开发者指南。See MySQL Connector/NET Developer Guide. |
| Objective Caml | Objective Caml MySQL 绑定OBjective Caml MySQL Bindings | libmysqlclient |
参见 Objective Caml 的 MySQL 绑定。See MySQL Bindings for Objective Caml. |
| Octave | GNU Octave 的数据库绑定Database bindings for GNU Octave | libmysqlclient |
请参阅 GNU Octave 的数据库绑定。See Database bindings for GNU Octave. |
| ODBC | Connector/ODBC | libmysqlclient |
请参阅 MySQL Connector/ODBC 开发者指南。See MySQL Connector/ODBC Developer Guide. |
| Perl | DBI/DBD::mysql |
libmysqlclient |
参见第 31.9 节,“MySQL Perl API”。See Section 31.9, “MySQL Perl API”. |
Net::MySQL |
原生驱动Native Driver | 请参阅 CPAN 上的 Net::MySQLSee
Net::MySQL
at CPAN |
|
| PHP | mysql,ext/mysql 接口(已弃用)mysql, ext/mysql interface
(deprecated) |
libmysqlclient |
请参阅 MySQL 与 PHP。See MySQL and PHP. |
mysqli,ext/mysqli 接口mysqli, ext/mysqli interface |
libmysqlclient |
请参阅 MySQL 与 PHP。See MySQL and PHP. | |
PDO_MYSQL |
libmysqlclient |
请参阅 MySQL 与 PHP。See MySQL and PHP. | |
| PDO mysqlnd | 原生驱动Native Driver | ||
| Python | Connector/Python | 原生驱动Native Driver | 请参阅 MySQL Connector/Python 开发者指南。See MySQL Connector/Python Developer Guide. |
| Python | Connector/Python C 扩展Connector/Python C Extension | libmysqlclient |
请参阅 MySQL Connector/Python 开发者指南。See MySQL Connector/Python Developer Guide. |
| MySQLdb | libmysqlclient |
请参阅 第 31.10 节,“MySQL Python API”。See Section 31.10, “MySQL Python API”. | |
| Ruby | mysql2 | libmysqlclient |
使用 libmysqlclient。请参阅 第 31.11 节,“MySQL Ruby APIs”。Uses libmysqlclient. See Section 31.11, “MySQL Ruby APIs”. |
| Scheme | Myscsh |
libmysqlclient |
请参阅 Myscsh。See
Myscsh. |
| SPL | sql_mysql |
libmysqlclient |
参见 sql_mysql 了解 SPL。See
sql_mysql
for SPL. |
| Tcl | MySQLtcl | libmysqlclient |
参见 第 31.12 节,“MySQL Tcl API”。See Section 31.12, “MySQL Tcl API”. |