Linux Tutorials - Herong's Tutorial Examples - v1.32, by Dr. Herong Yang
Install MySQL Connector/Python on CentOS
Provides a tutorial example on how to install MySQL Connector/Python on CentOS systems.
If you want to access MySQL database server from Python scripts, you can follow what I did on my CentOS 8 computer to install the MySQL Connector/Python module.
1. Install MySQL Connector/Python with "pip3" command.
herong$ sudo pip3 install mysql-connector-python Collecting mysql-connector-python Downloading https://files.pythonhosted.org/packages/d8/29/... Collecting dnspython==1.16.0 (from mysql-connector-python) Downloading https://files.pythonhosted.org/packages/ec/d3/... Collecting protobuf==3.6.1 (from mysql-connector-python) Downloading https://files.pythonhosted.org/packages/c2/f9/... Requirement already satisfied: six>=1.9 ... Requirement already satisfied: setuptools ... Installing collected packages: dnspython, protobuf, mysql-connector-python Found existing installation: protobuf 3.11.3 Successfully uninstalled protobuf-3.11.3 Successfully installed dnspython-1.16.0 mysql-connector-python-8.0.19 protobuf-3.6.1
2. If "pip3" command fails, install MySQL Connector/Python with "dnf/yum" command.
herong$ sudo yum install mysql-connector-python ...
3. If "dnf/yum" command fails, Go to MySQL Connector/Python download Web site at https://dev.mysql.com/downloads/connector/python/ to download the "Red Hat Enterprise Linux 8 / Oracle Linux 8 (x86, 64-bit), RPM Package". Then run the "rpm" command to install it.
herong$ sudo rpm -i ....rpm
4. Test MySQL Connector/Python with the following Python code:
herong$ python3 >>> import mysql.connector >>> con = mysql.connector.connect( user='herong', password='TopSecret', host='localhost') >>> con.close()
5. Read the MySQL Connector/Python Developer Guide at https://dev.mysql.com/doc/connector-python/en/ to learn more.
Table of Contents