Today, I installed the python module on ubuntu1804, mysqlclient reported an error, and recorded the solution
What is mysqlclient
- mysqlclient is a database driver for python to connect to MySQL, written in c language.
- Python also has a pymysql that is also connected to mysql data. These two modules are the same author. Why should I write two?
- Comparison of advantages and disadvantages of pymysql and mysqlclient
- One, pymysql
- 1) Realized by pure Python, simple installation (direct pip installation)
- 2) Due to the pure Python implementation, it can be well combined with the gevent framework
- Second, mysqlclient
- 1) It is a C extension module, compilation and installation may lead to various errors, obviously not convenient for pymysql
- 2) Fast speed; database driver recommended by python3
- 3. Current status
- Because of the trouble, there are more domestic pymysql.
- The problem that gevent cannot use mysqlclient, it is also said that you can use mysqlclient through gevent.hub
- Django is recommended to use mysqlclient, to maintain high efficiency
- One, pymysql
Error review
Installing mysqlclient under ubuntu really gave an error.
python3 -m pip install mysqlclient
The error content is as follows: EnvironmentError: mysql_config not found
Resolve errors
- Install missing libraries
sudo apt install libmysqlclient-dev
#centos下面使用,yum -y install mysql-devel
Then go back and install it.
- Direct apt installation When
apt installation, automatically install related dependent packages
#Debian and Ubuntu use it to provide both python-mysqldb andpython3-mysqldb packages.
sudo apt install python-mysqldb #python2
sudo apt install python3-mysqldb #python3