[How to Solve] ImportError: No module named MySQLdb

When MySQL DB is introduced into Python scripts, errors are often reported. It’s not easy to install on MAC, windows and CentOS before. Here’s a summary. First, follow these basic dependencies:

sudo yum install mysql-devel gcc python-devel

// Install the Python development version and its headers
yum install python-devel.x86_64 (for python2)
sudo yum install python3-devel (for python3)

Then try

yum install MySQL-python -y

If it still fails, continue to install MSYQL

sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm#install mysql镜像
sudo yum install mysql mysql-server mysql-libs mysql-server#install mysql

Then install MySQL python

yum install MySQL-python -y

In addition, if it is Python 3, you may need to install the following:

pip3 install mysqlclient==1.3.7
pip3 install PyMySQL

Similar Posts: