django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (timed out)")

学习骆昊大神的jackfrued/Python-100-Days

第42天

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (timed out)")

python manage.py migrate

这步总出错。

错误1:

cumysqlclient 1.3.13 or newer is required; you have 0.9.3

解决方案:

找到Python环境下 django包,并进入到backends下的mysql文件夹

找到base.py文件,注释掉 base.py 中如下部分(35/36行)
if version < (1, 3, 3):
     raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
 

错误2:

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (timed out)")

解决方案:

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (timed out)")

这里的host改为 本机地址127.0.0.1即可:

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (timed out)")