MySQL Connector/Python Developer Guide
Connector/Python source distributions are platform independent and can be used on any platform. Source distributions are packaged in two formats:
Zip archive format (.zip
file)
Compressed tar archive format
(.tar.gz
file)
Either packaging format can be used on any platform, but Zip archives are more commonly used on Windows systems and tar archives on Unix and Unix-like systems.
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, you must satisfy the following prerequisites.
Python 2.7 support was removed in Connector/Python 8.0.24, and Python 3.7 support was removed in Connector/Python 8.1.0.
Linux: A C/C++ compiler, such as gcc
Windows: Current version of Visual Studio
Protobuf C++ (version >= 4.21.1,<=4.21.12) for the C extension and/or Python's protobuf package for the pure Python implementation
Python development files
MySQL Server installed, including development files to compile the optional C Extension that interfaces with the MySQL C client library
You must install MySQL Server if it is not already present on your system. To obtain it, visit the MySQL download site.
A Connector/Python Zip archive (.zip
file) is available
from the Connector/Python download site (see
Section 4.1, “Obtaining Connector/Python”).
To install Connector/Python from a Zip archive, download the latest version and follow these steps:
Unpack the Zip archive in the intended installation directory
(for example, C:\mysql-connector\
) using
WinZip or another tool that can read
.zip
files.
Start a console window and change location to the folder where you unpacked the Zip archive:
$> cd C:\mysql-connector\
Inside the Connector/Python folder, perform the installation using this command:
$> python setup.py install
To include the C Extension (available as of Connector/Python 2.1.1), use this command instead:
$> python setup.py install --with-mysql-capi="path_name
"
The argument to --with-mysql-capi
is the path
to the installation directory of MySQL Server.
To see all options and commands supported by
setup.py
, use this command:
$> python setup.py --help
For Unix and Unix-like systems such as Linux, Solaris, macOS, and
FreeBSD, a Connector/Python tar archive
(.tar.gz
file) is available from the Connector/Python
download site (see Section 4.1, “Obtaining Connector/Python”).
To install Connector/Python from a tar archive, download
the latest version (denoted here as
VER
), and execute these commands:
$>tar xzf mysql-connector-python-
$>VER
.tar.gzcd mysql-connector-python-
$>VER
sudo python setup.py install \ --with-protobuf-include-dir=
/dir/to/protobuf/include
\ --with-protobuf-lib-dir=/dir/to/protobuf/lib
\ --with-protoc=/path/to/protoc/binary
To include the C Extension (available as of Connector/Python 2.1.1) that
interfaces with the MySQL C client library, also add the
--with-mysql-capi
such as:
$>sudo python setup.py install \ --with-protobuf-include-dir=
\ --with-mysql-capi="/dir/to/protobuf/include
\ --with-protobuf-lib-dir=/dir/to/protobuf/lib
\ --with-protoc=/path/to/protoc/binary
path_name
The argument to --with-mysql-capi
is the path to
the installation directory of MySQL Server, or the path to the
mysql_config command.
To see all options and commands supported by
setup.py
, use this command:
$> python setup.py --help