Table of Contents
Connector/Python runs on any platform where Python is installed. Python comes preinstalled on most Unix and Unix-like systems, such as Linux, OS X, and FreeBSD. On Microsoft Windows, a Python installer is available at the Python Download website. If necessary, download and install Python for Windows before attempting to install Connector/Python.
Connector/Python requires python to be in the system's
PATH and installation fails if
python cannot be located. On Unix and Unix-like
systems, python is normally located in a
directory included in the default PATH setting.
On Windows, if you install Python, either enable Add
python.exe to Path during the installation process, or
manually add the directory containing
python.exe yourself.
For more information about installation and configuration of Python on Windows, see Using Python on Windows in the Python documentation.
Connector/Python implements the MySQL client/server protocol two ways:
As pure Python. This implementation of the protocol does not require any other MySQL client libraries or other components.
As a C Extension that interfaces with the MySQL C client library. This implementation of the protocol is dependent on the client library, but can use the library provided by either MySQL Connector/C or MySQL Server packages (see MySQL C API Implementations). The C Extension is available as of Connector/Python 2.1.1.
Neither implementation of the client/server protocol has any third-party dependencies. However, if you need SSL support, verify that your Python installation has been compiled using the OpenSSL libraries.
Installation of Connector/Python is similar on every platform and follows the standard Python Distribution Utilities or Distutils. Distributions are available in native format for some platforms, such as RPM packages for Linux.
Python terminology regarding distributions:
Built Distribution: A package created in the native packaging format intended for a given platform. It contains both sources and platform-independent bytecode. Connector/Python binary distributions are built distributions.
Source Distribution: A distribution that contains only source files and is generally platform independent.
Packages are available at the Connector/Python download site. For some packaging formats, there are different packages for different versions of Python; choose the one appropriate for the version of Python installed on your system.
Connector/Python installers in native package formats are available for Windows and for Unix and Unix-like systems:
Windows: MSI installer package
Linux: Yum repository for EL6 and EL7 and Fedora 20 and 21; RPM packages for Oracle Linux, Red Hat, and SuSE; Debian packages for Debian and Ubuntu
OS X: Disk image package with PKG installer
You may need root or administrator privileges
to perform the installation operation.
As of Connector/Python 2.1.1, binary distributions are available that include a C Extension that interfaces with the MySQL C client library. Some packaging types have a single distribution file that includes the pure-Python Connector/Python code together with the C Extension. (Windows MSI and OS X Disk Image packages fall into this category.) Other packaging types have two related distribution files: One that includes the pure-Python Connector/Python code, and one that includes only the C Extension. For packaging types that have separate distribution files, install both distributions if you want to use the C Extension. The two files have related names, the difference being that the one that contains the C Extension has “cext” in the distribution file name.
Binary distributions that provide the C Extension are either statically linked to MySQL Connector/C or link to an already installed C client library provided by a Connector/C or MySQL Server installation. For those distributions that are not statically linked, you must install Connector/C or MySQL Server if it is not already present on your system. To obtain either product, visit the MySQL download site.
Connector/Python Windows MSI Installers (.msi files) are
available from the Connector/Python download site (see
Section 4.1, “Obtaining Connector/Python”). Choose an installer
appropriate for the version of Python installed on your system. As
of Connector/Python 2.1.1, MSI Installers include the C Extension; it need
not be installed separately.
To use the MSI Installer, launch it and follow the prompts in the screens it presents to install Connector/Python in the location of your choosing.
Alternatively, to run the installer from the command line, use
this command in a console window, where
VER and
PYVER are the respective
Connector/Python and Python version numbers in the installer file
name:
shell> msiexec /i mysql-connector-python-VER-pyPYVER.msi
Subsequent executions of Connector/Python using the MSI installer permit you to either repair or remove the existing Connector/Python installation.
For EL6 or EL7-based platforms and Fedora 19 or 20, you can install Connector/Python using the MySQL Yum repository (see Installing Additional MySQL Products and Components with Yum). You must have the MySQL Yum repository on your system's repository list (for details, see Adding the MySQL Yum Repository). To make sure that your Yum repository is up-to-date, use this command:
shell> sudo yum update mysql-community-release
Then install Connector/Python as follows:
shell> sudo yum install mysql-connector-python
Connector/Python Linux RPM packages (.rpm files) are
available from the Connector/Python download site (see
Section 4.1, “Obtaining Connector/Python”).
To install a Connector/Python RPM package (denoted here as
), use
this command:
PACKAGE.rpm
shell> rpm -i PACKAGE.rpm
To install the C Extension (available as of Connector/Python 2.1.1), install the corresponding package with “cext” in the package name.
RPM provides a feature to verify the integrity and authenticity of packages before installing them. To learn more, see Verifying Package Integrity Using MD5 Checksums or GnuPG.
Connector/Python Debian packages (.deb files) are
available for Debian or Debian-like Linux systems from the Connector/Python
download site (see Section 4.1, “Obtaining Connector/Python”).
To install a Connector/Python Debian package (denoted here as
), use
this command:
PACKAGE.deb
shell> dpkg -i PACKAGE.deb
To install the C Extension (available as of Connector/Python 2.1.1), install the corresponding package with “cext” in the package name.
Connector/Python OS X disk images (.dmg files) are
available from the Connector/Python download site (see
Section 4.1, “Obtaining Connector/Python”). As of Connector/Python 2.1.1,
OS X disk images include the C Extension; it need not be installed
separately.
Download the .dmg file and install Connector/Python by
opening it and double clicking the resulting
.pkg file.
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.
As of Connector/Python 2.1.1, 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.
Prerequisites for Windows systems:
Correct version of Visual Studio: VS 2009 for Python 2.7, VS 2010 for Python 3.3
Python development files
MySQL Connector/C or MySQL Server installed, including development files
Prerequisites for Unix and Unix-like systems:
A C/C++ compiler, such as gcc
Python development files
MySQL Connector/C or MySQL Server installed, including development files
You must install Connector/C or MySQL Server if it is not already present on your system. To obtain either product, visit the MySQL download site.
For certain platforms, MySQL development files are provided in separate packages. This is true for RPM and Debian packages, for example.
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:
shell> cd C:\mysql-connector\
Inside the Connector/Python folder, perform the installation using this command:
shell> python setup.py install
To include the C Extension (available as of Connector/Python 2.1.1), use this command instead:
shell> python setup.py install --with-mysql-capi="path_name"
The argument to --with-mysql-capi is the path
to the installation directory of either MySQL Connector/C or MySQL Server.
To see all options and commands supported by
setup.py, use this command:
shell> python setup.py --help
For Unix and Unix-like systems such as Linux, Solaris, OS X, 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:
shell>tar xzf mysql-connector-python-shell>VER.tar.gzcd mysql-connector-python-shell>VERsudo python setup.py install
To include the C Extension (available as of Connector/Python 2.1.1), use this command instead:
shell> sudo python setup.py install --with-mysql-capi=value
The argument to --with-mysql-capi is the path to
the installation directory of either MySQL Connector/C or MySQL Server, or the
path to the mysql_config command.
To see all options and commands supported by
setup.py, use this command:
shell> python setup.py --help
On Windows, the default Connector/Python installation location is
C:\Python,
where X.Y\Lib\site-packages\X.Y is the Python version you
used to install the connector.
On Unix-like systems, the default Connector/Python installation location is
/,
where prefix/pythonX.Y/site-packages/prefix is the location where
Python is installed and X.Y is the
Python version. See
How
installation works in the Python manual.
The C Extension is installed as
_mysql_connector.so in the
site-packages directory, not in the
mysql/connector directory.
Depending on your platform, the installation path might differ from the default. If you are not sure where Connector/Python is installed, do the following to determine its location. The output here shows installation locations as might be seen on OS X:
shell> python
>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib() # Python v2.x
/Library/Python/2.7/site-packages
>>> print(get_python_lib()) # Python v3.x
/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages
To test that your Connector/Python installation is working and able to connect to MySQL Server, you can run a very simple program where you supply the login credentials and host information required for the connection. For an example, see Section 5.1, “Connecting to MySQL Using Connector/Python”.