Send by LINE
B! Bookmarks in Hate-bu
Bookmarks in Pocket
RSS feeds

Python: Connect to MySQL / MarriaDB

Other language site
No available translations found
Google Translate
python logo

Install mysql-connector-python package to Python 2.7 installed on CentOS and connect to MySQL / MarriaDB.
It can also be used with Python 3 series.

Install the connector that connects the database (MySQL, MariaDB) to python 2.7 which is installed as a standard on CentOS (7.4.1708).

Install using pip command

Install using pip command which is package management of python.

pip install mysql-connector

I failed. The error contents are as follows.

running install

Not Installing MySQL C Extension

running build

# Python architecture: 64-bit
# Python ARCH_64BIT: True
Unable to find Protobuf include directory.

' ----------------------------------------

Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-eUfgeL/mysql-connector/';f=getattr(tokenize, 'open', open)(__file__);'\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-HBetzs-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-eUfgeL/mysql-connector/

ERROR code 1 is returned by installing the pip command. When I looked at the MySQL site there seems to be a manual installation method.

I decided to change the installation method to manual.

Manual installation

yum install mysql-connector-python

For the installation method, refer to the document of the MySQL website.

Installation confirmation

Check with the pip command.

pip list
backports.ssl-match-hostname (
certifi (2017.4.17)
chardet (3.0.4)
configobj (4.7.2)
decorator (3.4.0)
idna (2.5)
iniparse (0.4)
kitchen (1.1.1)
mysql-connector-python (1.1.6)


Operation check

python -c 'import mysql.connector'

If it is executed and nothing is displayed on the standard output, it is working normally.

Leave a Reply