MySQL Connector/Python Developer Guide
The Connector/Python source distribution is platform independent, and is
packaged in the compressed tar
archive format
(.tar.gz
file). See
Obtaining
Connector/Python) on how to download them.
Source distributions include the C Extension that interfaces with the MySQL C client library. You can build the distribution with or without support for this extension. To build Connector/Python with support for the C Extension, the following prerequisites must be satisfied:
Compiling tools:
For Linux platforms: A C/C++ compiler, such as gcc.
For Windows platforms: Current version of Visual Studio.
Python development files.
For installing the classic interface only: MySQL Server binaries (server may be installed or not installed on the system), including development files (to obtain the MySQL Server binaries, visit the MySQL download site).
For installing the X DevAPI interface only: Protobuf C++ (version
5.29.4
).
pip
We recommend leveraging python virtual environments to encapsulate the package installation instead of installing packages directly into the Python system environment.
For installing the classic interface:
Download the latest version of the sdist
of
Connector/Python for the classic MySQL protocol, whose name is
in the format of
mysql_connector_python-x.y.z.tar.gz
.
Optional: To include the C Extension, use
these steps to provide the path to the installation directory
of MySQL Server (or to the folder where the server binaries
are located) with the MYSQL_CAPI
system
variable before running the installation step. On Linux
platforms:
$ export MYSQL_CAPI=<path to server binaries>
On Windows platforms:
> $env:MYSQL_CAPI=<path to server binaries>
It is not required that the server is actually installed on the system; for compiling the C-extension, the presence of libraries are sufficient
Perform the installation using this command:
pip install ./mysql_connector_python-x.y.z.tar.gz
DO NOT use mysql-connector-python
instead
of ./mysql_connector_python-x.y.z.tar.gz
,
as the former will install the WHEEL package from the PyPI
repository, and the latter will install the local WHEEL that
is compiled from the source code.
For installing X DevAPI:
Download the latest version of the sdist
of
Connector/Python for the MySQL X Protocol, whose name is in
the format of
mysqlx_connector_python-x.y.z.tar.gz
.
Optional: To include the Protobuf
C-Extension, use these commands on Linux platforms
to provide the paths to the Protobuf folders by the
MYSQLXPB_*
system variables before the
installation step:
$ export MYSQLXPB_PROTOBUF=<path to protobuf binaries>
$ export MYSQLXPB_PROTOBUF_INCLUDE_DIR="${MYSQLXPB_PROTOBUF}/include"
$ export MYSQLXPB_PROTOBUF_LIB_DIR="${MYSQLXPB_PROTOBUF}/lib"
$ export MYSQLXPB_PROTOC="${MYSQLXPB_PROTOBUF}/bin/protoc"
Or these commands on Windows platforms:
> $env:PROTOBUF=<path to protobuf binaries>
> $env:PROTOBUF_INCLUDE_DIR=$env:PROTOBUF+"\include"
> $env:PROTOBUF_LIB_DIR=$env:PROTOBUF+"\lib"
> $env:PROTOC=$env:PROTOBUF+"\bin\protoc.exe"
Perform the installation using this command:
pip install ./mysqlx_connector_python-x.y.z.tar.gz
DO NOT use mysqlx-connector-python
instead of
./mysqlx_connector_python-x.y.z.tar.gz
,
as the former will install the WHEEL package from the PyPI
repository, and the latter will install the local WHEEL that
is compiled from the source code.