PYnative

Python Programming

  • Learn Python
  • Exercises
  • Quizzes
  • Code Editor
  • Tricks
Home » Python » Databases » Install MySQL Connector Python on Windows, MacOs, Linux, Unix and Ubuntu

Install MySQL Connector Python on Windows, MacOs, Linux, Unix and Ubuntu

Updated on: March 9, 2021 | 6 Comments

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

  • Download and Install MySQL Connector Python on Windows
    • Install MySQL Connector Python on Windows using a Source Code Distribution:-
    • Verifying MySQL Connector/Python installation on windows
  • Download and Install MySQL Connector Python on Linux
    • Verifying MySQL Connector Python installation on Linux
  • Download and Install MySQL Connector Python on MacOs
  • Install MySQL Connector Python on Ubuntu
  • Next Steps:

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 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 Python MySQL VersionsPython Versions
8.08.0, 5.7, 5.6, 5.53.6, 3.5, 3.4, 2.7
2.25.7, 5.6, 5.53.5, 3.4, 2.7
2.15.7, 5.6, 5.53.5, 3.4, 2.7, 2.6
2.05.7, 5.6, 5.53.5, 3.4, 2.7, 2.6
1.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 connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598). 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

download MySQL connector python for windows
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

select MySQL connector python platform independent zip for windows
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.

begin download MySQL connector python zip file for windows
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.

python MySQL connector python installation completed for windows
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 C:\Python.Version\Lib\sitepackages\ . Here Python.version is the Python version you used to install the connector.
  • Type importing MySQL connector using import mysql.connector. 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.

download MySQL connector python for Linux
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
MySQL connector python platform independent tar for Linux
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.

MySQL connector python begin your download for Linux
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 shell> sudo python setup.py install command to install MySQL connector python on Linux.
  • To see all options and commands supported by setup.py use python setup.py --help 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 /prefix/python.VERSION/site-packages/ where prefix is the location where Python installed, and VERSION is the Python version.
  • Type import mysql.connector 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 hereDownload and install mysql connector python macOs
  • 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).
install MySQL connector python on Ubuntu
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.

    sudo apt-get install -f
  • 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.

    Filed Under: Python, Python Databases

    Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

    TweetF  sharein  shareP  Pin

    About Vishal

    Founder of PYnative.com I am a Python developer and I love to write articles to help developers. Follow me on Twitter. All the best for your future Python endeavors!

    Related Tutorial Topics:

    Python Python Databases

    Python Exercises and Quizzes

    Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

    • 15+ Topic-specific Exercises and Quizzes
    • Each Exercise contains 10 questions
    • Each Quiz contains 12-15 MCQ
    Exercises
    Quizzes

    Posted In

    Python Python Databases
    TweetF  sharein  shareP  Pin

      Python MySQL

    • Python MySQL Connection Guide
    • Python MySQL Insert
    • Python MySQL Select
    • Python MySQL Update
    • Python MySQL Delete
    • Call MySQL Stored Procedure
    • Python MySQL Parameterized Query
    • Python MySQL Transactions
    • Python MySQL Connection Pooling
    • Python MySQL BLOB
    • Python Database Exercise

    All Python Topics

    Python Basics Python Exercises Python Quizzes Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

    About PYnative

    PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

    Explore Python

    • Learn Python
    • Python Basics
    • Python Databases
    • Python Exercises
    • Python Quizzes
    • Online Python Code Editor
    • Python Tricks

    Follow Us

    To get New Python Tutorials, Exercises, and Quizzes

    • Twitter
    • Facebook
    • Sitemap

    Legal Stuff

    • About Us
    • Contact Us

    We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our Terms Of Use, Cookie Policy, and Privacy Policy.

    Copyright © 2018–2023 pynative.com