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. Show
Further Reading:
Table of contentsPrerequisites before installing MySQL Connector Python
Note: – MySQL Connector Python requires Python to be in the system’s PATH. Installation fails if it doesn’t find Python.
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. 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.
Python MySQL Connector VersionsPlease 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.6Great! Now you can choose the version as per your need. Pip Command to install MySQL Connector pythonIt 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.
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.
If you are facing pip install fails error with 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.
Verifying MySQL Connector Python installationYou should get the following messages after running pip command: –
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 WindowsThere are two ways to install MySQL Connector Python on windows.
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
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 windowsClick 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 to download MySQL connector python zip file for windowsNote: 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: –
You should get the following screen after this command. Python MySQL connector python installation completed for windowsVerifying MySQL Connector/Python installation on windowsTo 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:
Download and Install MySQL Connector Python on LinuxThere are two ways to install MySQL Connector Python on For Unix and Unix-like systems such as Linux, Solaris, macOS, and FreeBSD.
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
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 LinuxAfter the download is complete, please follow the below steps to install: –
Verifying MySQL Connector Python installation on LinuxTo verify the installation, use the following steps:
Download and Install MySQL Connector Python on MacOsYou can Installing MySQL Connector Python on macOS Using a Disk Image.
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 UbuntuUse 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.
sudo dpkg -i /path_to_downloaded_deb_file After this run the following command. 0Next Steps:To practice what you learned in this article, Please solve a Python Database Exercise project to Practice and master the Python Database operations. |