34

I use sqlalchemy to access MySQL in my Python project. sqlalchemy's conf is like this:

dialect=mysql
driver=mysqlconnector

So I need to install the Python module mysql connector via pip. Any help?

Michael
  • 8,362
  • 6
  • 61
  • 88
Codefor
  • 1,318
  • 2
  • 13
  • 22
  • 6
    The official package name now is **`mysql-connector-python`**, so use `pip install mysql-connector-python` – YaOzI Nov 13 '18 at 02:00

6 Answers6

55

If loading via pip install mysql-connector and leads an error Unable to find Protobuf include directory then this would be useful pip install mysql-connector==2.1.4

mysql-connector is obsolete, so use pip install mysql-connector-python. Same here

Partha Sen
  • 2,759
  • 1
  • 18
  • 17
  • Requirements mysql-connector (version >= 2.2.3) requires Protobuf C++ (version >= 2.6.0) see https://github.com/sanpingz/mysql-connector – Codefor Jun 14 '17 at 05:20
  • I have edited and added to https://stackoverflow.com/questions/46215390/unable-to-find-protobuf-include-directory-when-i-use-pip-install-mysql-connec – Partha Sen Sep 14 '17 at 09:37
  • Oracle has finally decided to upload their package (including wheels) to PyPI. So it's now "mysql-connector-python" instead of the deprecated unofficial repackage of "mysql-connector". https://pypi.org/project/mysql-connector-python/ – Zhuoyun Wei Jun 19 '19 at 06:01
28

To install the official MySQL Connector for Python, please use the name mysql-connector-python:

pip install mysql-connector-python

Some further discussion, when we pip search for mysql-connector at this time (Nov, 2018), the most related results shown as follow:

$ pip search mysql-connector | grep ^mysql-connector
mysql-connector (2.1.6)                  - MySQL driver written in Python
mysql-connector-python (8.0.13)          - MySQL driver written in Python
mysql-connector-repackaged (0.3.1)       - MySQL driver written in Python
mysql-connector-async-dd (2.0.2)         - mysql async connection
mysql-connector-python-rf (2.2.2)        - MySQL driver written in Python
mysql-connector-python-dd (2.0.2)        - MySQL driver written in Python
  • mysql-connector (2.1.6) is provided on PyPI when MySQL didn't provide their official pip install on PyPI at beginning (which was inconvenient). But it is a fork, and is stopped updating, so

    pip install mysql-connector
    

    will install this obsolete version.

  • And now mysql-connector-python (8.0.13) on PyPI is the official package maintained by MySQL, so this is the one we should install.

YaOzI
  • 16,128
  • 9
  • 76
  • 72
26
pip install mysql-connector

Last but not least,You can also install mysql-connector via source code

Download source code from: https://dev.mysql.com/downloads/connector/python/

dkb
  • 4,389
  • 4
  • 36
  • 54
Codefor
  • 1,318
  • 2
  • 13
  • 22
  • related pages: https://pypi.python.org/pypi/mysql-connector https://github.com/sanpingz/mysql-connector – Codefor Jun 14 '17 at 05:21
7

execute following command from your terminal

sudo pip install --allow-external mysql-connector-python mysql-connector-python
Zaheer Khorajiya
  • 466
  • 3
  • 11
1

For Windows

pip install mysql-connector

For Ubuntu /Linux

sudo apt-get install python3-pymysql

Umesh Yadav
  • 1,042
  • 9
  • 17
0

First install setuptools

sudo pip install setuptools

Then install mysql-connector

sudo pip install mysql-connector

If using Python3, then replace pip by pip3