Django2.2 pip安装Mysql模块mysql_config缺失问题
续上回安装完python和pip后就开始拉代码,执行数据库迁移
在执行迁移的时候出现以下错误:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
缺少了Mysql模块,pip安装即可
ps:最新安装的是mysqlclient 而非 pymysql
[root@vultr ~] pip install mysqlclient
错误摘要如下:
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-knr3eh_4/mysqlclient/
然而重点在mysql_config这里
解决方法是将mysql_config挂载/usr/local/bin/mysql_config
然而看了下 /usr/local/mysql/bin/ 根本没mysql_config这个文件
需要安装mysql-devel 安装完后会自动生成 (没该问题的自动跳到下一条)
[root@vultr ~]# yum install mysql-devel
挂载
[root@vultr ~]# ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
重新安装mysqlclient
[root@vultr ~]# pip install mysqlclient
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.2.post1
最后记得到项目的 /yourProjectName/__init__.py加上一行
import MySQLdb