Chapter 29 Connectors and APIs

Table of Contents

29.1 MySQL Connector/C++
29.2 MySQL Connector/J
29.3 MySQL Connector/NET
29.4 MySQL Connector/ODBC
29.5 MySQL Connector/Python
29.6 MySQL Connector/Node.js
29.7 MySQL C API
29.8 MySQL PHP API
29.9 MySQL Perl API
29.10 MySQL Python API
29.11 MySQL Ruby APIs
29.11.1 The MySQL/Ruby API
29.11.2 The Ruby/MySQL API
29.12 MySQL Tcl API
29.13 MySQL Eiffel Wrapper

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 develops a number of connectors:

The MySQL C 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 is included in MySQL distributions distributions.

See also MySQL C API Implementations.

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 4.7, “Program Development Utilities”.

Third-Party MySQL APIs

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.

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:

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

Table 29.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 8.0 C API Developer Guide.
C++ Connector/C++ libmysqlclient See MySQL Connector/C++ 8.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 29.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 5.1 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 29.9, “MySQL Perl API”.
Net::MySQL Native Driver See Net::MySQL at CPAN
PHP mysql, ext/mysql interface (deprecated) libmysqlclient See Original MySQL API.
mysqli, ext/mysqli interface libmysqlclient See MySQL Improved Extension.
PDO_MYSQL libmysqlclient See MySQL Functions (PDO_MYSQL).
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 29.10, “MySQL Python API”.
Ruby MySQL/Ruby libmysqlclient Uses libmysqlclient. See Section 29.11.1, “The MySQL/Ruby API”.
Ruby/MySQL Native Driver See Section 29.11.2, “The Ruby/MySQL API”.
Scheme Myscsh libmysqlclient See Myscsh.
SPL sql_mysql libmysqlclient See sql_mysql for SPL.
Tcl MySQLtcl libmysqlclient See Section 29.12, “MySQL Tcl API”.

29.1 MySQL Connector/C++

The MySQL Connector/C++ manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.2 MySQL Connector/J

The MySQL Connector/J manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.3 MySQL Connector/NET

The MySQL Connector/NET manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.4 MySQL Connector/ODBC

The MySQL Connector/ODBC manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.5 MySQL Connector/Python

The MySQL Connector/Python manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.6 MySQL Connector/Node.js

The MySQL Connector/Node.js manual is published in standalone form, not as part of the MySQL Reference Manual. For information, see these documents:

29.7 MySQL C API

The MySQL C API Developer Guide is published in standalone form, not as part of the MySQL Reference Manual. See MySQL 8.0 C API Developer Guide.

29.8 MySQL PHP API

The MySQL PHP API manual is now published in standalone form, not as part of the MySQL Reference Manual. See MySQL and PHP.

29.9 MySQL Perl API

The Perl DBI module provides a generic interface for database access. You can write a DBI script that works with many different database engines without change. To use DBI with MySQL, install the following:

  1. The DBI module.

  2. The DBD::mysql module. This is the DataBase Driver (DBD) module for Perl.

  3. Optionally, the DBD module for any other type of database server you want to access.

Perl DBI is the recommended Perl interface. It replaces an older interface called mysqlperl, which should be considered obsolete.

These sections contain information about using Perl with MySQL and writing MySQL applications in Perl:

DBI information is available at the command line, online, or in printed form:

  • Once you have the DBI and DBD::mysql modules installed, you can get information about them at the command line with the perldoc command:

    shell> perldoc DBI
    shell> perldoc DBI::FAQ
    shell> perldoc DBD::mysql
    

    You can also use pod2man, pod2html, and so on to translate this information into other formats.

  • For online information about Perl DBI, visit the DBI website, http://dbi.perl.org/. That site hosts a general DBI mailing list.

  • For printed information, the official DBI book is Programming the Perl DBI (Alligator Descartes and Tim Bunce, O'Reilly & Associates, 2000). Information about the book is available at the DBI website, http://dbi.perl.org/.

29.10 MySQL Python API

MySQLdb is a third-party driver that provides MySQL support for Python, compliant with the Python DB API version 2.0. It can be found at http://sourceforge.net/projects/mysql-python/.

The new MySQL Connector/Python component provides an interface to the same Python API, and is built into the MySQL Server and supported by Oracle. See MySQL Connector/Python Developer Guide for details on the Connector, as well as coding guidelines for Python applications and sample Python code.

29.11 MySQL Ruby APIs

Two APIs are available for Ruby programmers developing MySQL applications:

For background and syntax information about the Ruby language, see Ruby Programming Language.

29.11.1 The MySQL/Ruby API

The MySQL/Ruby module provides access to MySQL databases using Ruby through libmysqlclient.

For information on installing the module, and the functions exposed, see MySQL/Ruby.

29.11.2 The Ruby/MySQL API

The Ruby/MySQL module provides access to MySQL databases using Ruby through a native driver interface using the MySQL network protocol.

For information on installing the module, and the functions exposed, see Ruby/MySQL.

29.12 MySQL Tcl API

MySQLtcl is a simple API for accessing a MySQL database server from the Tcl programming language. It can be found at http://www.xdobry.de/mysqltcl/.

29.13 MySQL Eiffel Wrapper

Eiffel MySQL is an interface to the MySQL database server using the Eiffel programming language, written by Michael Ravits. It can be found at http://efsa.sourceforge.net/archive/ravits/mysql.htm.