Cara menggunakan mysql.connector.connect python ssl

In this lesson, You will learn how to Install MySQL Connector Python on Windows, macOS, Linux, Unix, and Ubuntu using pip and vis source code. To connect to a MySQL server from Python, you need a database driver (module). MySQL Connector Python is the official Oracle-supported driver to connect MySQL through Python.

Further Reading:

  • Solve Python MySQL Exercise
  • Read Python MySQL Tutorial (Complete Guide)

Table of contents

Prerequisites before installing MySQL Connector Python

  • You need root or administrator privileges to perform the installation process.
  • Python must be installed on your machine.

Note: – MySQL Connector Python requires Python to be in the system’s PATH. Installation fails if it doesn’t find Python.

  • Python is generally located in a directory included in the default PATH setting on Unix and Unix-like systems.
  • On Windows, If Python doesn’t exist in the system’s PATH, please manually add the directory containing python.exe yourself.

This article applies to: – 


Platform(s): 64-bit Windows, Windows 10, Windows 7, Windows 8, Windows Vista, Windows XP, Linux, Ubuntu Linux, Debian Linux, SUSE Linux, Red Hat Linux, Fedora, MacOs.
Python version(s): Python 2 and 3
MySQL Version(s): Greater than 4.1

Ways to install MySQL Connector Python

There are multiple ways to install Oracle’s MySQL Connector Python on your machine. The following are a few ways.

  • Install MySQL Connector Python using the
    pip install mysql-connector-python==8.0.11
    1 command
  • Install MySQL connector python via source code (via ZIP or TAR file)
  • Use Built Distribution A package created in the native packaging format intended for a given platform. For example, RPM packages for Linux or MSI installer for windows.

Python MySQL Connector Versions

Please refer to the following table of MySQL connector Python versions. You need to install a module that is compatible with your Python version.

MySQL Connector PythonMySQL VersionsPython Versions8.08.0, 5.7, 5.6, 5.53.6, 3.5, 3.4, 2.72.25.7, 5.6, 5.53.5, 3.4, 2.72.15.7, 5.6, 5.53.5, 3.4, 2.7, 2.62.05.7, 5.6, 5.53.5, 3.4, 2.7, 2.61.25.7, 5.6, 5.5 (5.1, 5.0, 4.1)3.4, 3.3, 3.2, 3.1, 2.7, 2.6

Great! Now you can choose the version as per your need.

Pip Command to install MySQL Connector python

It is always accessible and straightforward to install any module using pip in Python. MySQL Connector Python is available on pypi.org, so you can install it using the pip command.

pip install mysql-connector-python

If you are facing any problem while installing, please mention the module’s version and then try to install it again. Refer to the above table to install the correct version.

pip install mysql-connector-python==8.0.11

If you are facing pip install fails error with

pip install mysql-connector-python==8.0.11
2. You can solve this error.

You can ignore SSL errors by setting pypi.org and files.pythonhosted.org as trusted hosts. Please try following the pip command to install MySQL Connector Python.

python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --trusted-host pypi.python.org mysql-connector-python

Verifying MySQL Connector Python installation

You should get the following messages after running pip command: –

  • Collecting mysql-connector-python
  • Downloading packages.
  • Requirement already satisfied: setup tools in D:python\python37-32\lib\site-packages.
  • Installing collected packages:  mysql-connector-python
  • Successfully installed mysql-connector-python-8.0.13

Verify MySQL Connector Python installation by Connecting to MySQL Using MySQL Connector Python.


If you are unable to install using pip you can install using the following approaches.

Download and Install MySQL Connector Python on Windows

There are two ways to install MySQL Connector Python on windows.

  1. Install using Source Code Distribution ( Platform Independent and Architecture Independent ZIP Archive)
  2. Install using Built Distribution i.e., MSI installer

Install MySQL Connector Python on Windows using a Source Code Distribution:-

Follow below instruction to download Platform Independent ZIP. Go to download MySQL Connector Python for windows from here

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
download MySQL connector python for windows

  • Abobe URL automatically opens the latest version of MySQL Connector Python.
  • If you want to use the older version which is compatible with your python version, then select “Looking for previous GA versions” option which you can find at the right side.
  • If you want to check which version of MySQL Connector Python is compatible with your python version, refer to the above table.

I am downloading 2.1.7 because I am using Python 3.5. Select Platform independent from the drop-down list

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
select MySQL connector python platform-independent zip for windows

Click on the “download” button to download the ZIP file on your machine. After clicking download you get the below screen, click on No Thanks, start the download option.

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
begin to download MySQL connector python zip file for windows

Note: If you want to download the latest version, i.e. 8.0.1 then select “Looking for the latest GA versions” option which you can find at the right side.

After the download is complete, please follow the below steps to install: –

  • Unpack or extract the Zip archive in the intended installation directory (for example, C:\mysql-connector\) using 7Zip or another tool that can read .zip files.
  • Start a console window and change the location to the folder where you unpacked the Zip archive:
    C:\> cd C:\mysql-connector\
  •  Inside the MySQL Connector Python folder, perform the installation using this command:
    C:\> python setup.py install

You should get the following screen after this command.

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
Python MySQL connector python installation completed for windows

Verifying MySQL Connector/Python installation on windows

To verify MySQL connection Python is installed and to make sure that it is working correctly and you can connect to the MySQL database server without any issues. To verify the installation use the following steps:

  • On Windows, the default MySQL Connector Python installation location is
    pip install mysql-connector-python==8.0.11
    3 . Here Python.version is the Python version you used to install the connector.
  • Type importing MySQL connector using
    pip install mysql-connector-python==8.0.11
    4. If it is executed successfully mean installation completed successfully.
  • Also, you can check that MySQL Connector Python installation is working and able to connect to MySQL Server by Connecting to MySQL Using MySQL Connector Python.

Download and Install MySQL Connector Python on Linux

There are two ways to install MySQL Connector Python on For Unix and Unix-like systems such as Linux, Solaris, macOS, and FreeBSD.

  1. Install using Source Code Distribution ( Platform Independent (Architecture Independent), TAR File)
  2. You can install using Built Distribution for Example RPM file.

Install MySQL Connector Python on Linux using Source Code Distribution. Follow the below instructions to download MySQL connector python Platform Independent TAR (tar.gz) file.

Go to download MySQL Connector Python for Linux from here it will open the below screen.

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
download MySQL connector python for Linux

  • It opens the latest version of MySQL connector python. Choose the Previous GA version from the right side if you want to install a version other than 8.0.1. you can refer to the above table to check which version is compatible with your python version.
  • Select Platform independent TAR from the “Select Operating System” drop-down list. I am downloading 2.1.7 because I am using Python 3.5

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
MySQL connector python platform-independent tar for Linux

Choose the TAR archive file and click on the download button. You should get the following screen, click on the start of my download.

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
MySQL connector python begin your download for Linux

After the download is complete, please follow the below steps to install: –

  • Untar the downloaded tar.gz file. Use below command to untar.
    shell>tar xzf mysql-connector-python-VERSION.tar.gz
  • Change to the directory where you extracted a tar file
    shell> cd mysql-connector-python-VERSION
  • Execute
    pip install mysql-connector-python==8.0.11
    5 command to install MySQL connector python on Linux.
  • To see all options and commands supported by setup.py use
    pip install mysql-connector-python==8.0.11
    6 command

Verifying MySQL Connector Python installation on Linux

To verify the installation, use the following steps:

  • On Unix-like systems, the default Connector/Python installation location is
    pip install mysql-connector-python==8.0.11
    7 where prefix is the location where Python installed, and VERSION is the Python version.
  • Type
    pip install mysql-connector-python==8.0.11
    4 and execute the program. If it is executed successfully mean installation completed successfully.
  • Also, you can check that MySQL Connector Python installation is working and able to connect to MySQL Server by Connecting to MySQL Using MySQL Connector Python.

Download and Install MySQL Connector Python on MacOs

You can Installing MySQL Connector Python on macOS Using a Disk Image.

  • Go to download MySQL Connector python for macOS from here
    Cara menggunakan mysql.connector.connect python ssl
    Cara menggunakan mysql.connector.connect python ssl
  • Refer the above table to check which version is compatible with your python version
  • Download the mysql-connector-python-8.0.11-macos10.13.dmg file. it is an architecture Independent DMG file.
  • .Install the downloaded MySQL Connector Python by opening it and double-clicking the resulting .pkg file.

Verifying MySQL Connector Python installation on macOS

Check that MySQL Connector Python installation is working and able to connect to MySQL Server by Connecting to MySQL Using MySQL Connector Python.

Install MySQL Connector Python on Ubuntu

Use the following command to install MySQL connector Python on Ubuntu.

sudo apt-get install mysql-connector-python

After this run the following command.

pip install mysql-connector-python

You can replace pip with pip3 if the command fails in Python3. If the above approach doesn’t work, you can still install it on Ubuntu using the source code.

  • Go to download MySQL Connector python for Ubuntu from here.
  • Select the Operating system Ubuntu Linux from the drop-down.
  • Select the OS version as an architecture-independent. I am selecting Ubuntu-Linux 16.04 (architecture-independent).
  •  You should get two entries fro DEB Package python for MySQL Connector Python (For python 2 and Python 3).

Cara menggunakan mysql.connector.connect python ssl
Cara menggunakan mysql.connector.connect python ssl
install MySQL connector python on Ubuntu

  • Download the listed DEB package and install it using the following commands.
  • First, unpack the DEB file and then install it.
    sudo dpkg -i /path_to_downloaded_deb_file

    After this run the following command.

    pip install mysql-connector-python==8.0.11
    0
  • You are now done with installing MySQL Connector Python on Ubuntu.
  • Next Steps:

    To practice what you learned in this article, Please solve a Python Database Exercise project to Practice and master the Python Database operations.