温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading ini

python - django.db.utils.OperationalError:(2013年,“握手时与MySQL服务器的连接丢失:读取ini

发布于 2020-03-27 11:45:49

我正在使用django开发一个应用程序以将其推送到Heroku,并且尝试将mysql中的数据库迁移到heroku时,我安装了mysql-python,并且在尝试运行服务器时遇到了以下错误:

django.db.utils.OperationalError:(2013年,“握手时与MySQL服务器的连接丢失:读取初始通信数据包”,系统错误:0”)

(我启用了虚拟环境)。
奇怪的是,即使我已经安装了该软件包,该软件包也安装了python。
我发现它没有安装django和以前安装的几个模块,甚至是pip!

我重新安装了模块,但是现在当我运行服务器时,上面出现了该错误。
如果我从另一个应用程序目录运行服务器,则数据库运行良好。
它可能与我安装在目录中的内容有关,或者可能被奇怪的软件包覆盖了吗?

这是我的点冻结结果:

certifi==2019.6.16<br>
dj-database-url==0.5.0<br>
Django==2.2.3<br>
django-heroku==0.3.1<br>
gunicorn==19.9.0<br>
mysql-connector-python==8.0.16<br>
mysqlclient==1.4.2.post1<br>
protobuf==3.6.0<br>
psycopg2==2.8.3<br>
PyMySQL==0.9.3<br>
python-decouple==3.1<br>
pytz==2019.1<br>
six==1.12.0<br>
sqlparse==0.3.0<br>
whitenoise==4.1.2<br>
wincertstore==0.2<br>

现在,我将删除该项目并尝试重新构建它,只要我了解,搞砸该项目的原因就是我尝试安装mysql-python。

Collecting mysql-python Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Building wheels for collected packages: mysql-python Building wheel for mysql-python (setup.py) ... error ERROR: Complete output from command 'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;file='"'"'C:\Users\Tommaso\AppData\Local\Temp\pip-install-yr8h0ec1\mysql-python\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Tommaso\AppData\Local\Temp\pip-wheel-ywwxryy8' --python-tag cp37: ERROR: running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.7 copying _mysql_exceptions.py -> build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\MySQLdb copying MySQLdb__init__.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb creating build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants running build_ext
building '_mysql' extension creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release_mysql.obj /Zl _mysql.c
_mysql.c(42): fatal error C1083: Non è possibile aprire il file inclusione: 'config-win.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2 ----------------------------------------
ERROR: Failed building wheel for mysql-python Running setup.py clean for mysql-python Failed to build mysql-python Installing collected packages: mysql-python Running setup.py install for mysql-python ... error ERROR: Complete output from command 'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;file='"'"'C:\Users\Tommaso\AppData\Local\Temp\pip-install-yr8h0ec1\mysql-python\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Tommaso\AppData\Local\Temp\pip-record-dwqliwhp\install-record.txt' --single-version-externally-managed --compile: ERROR: running install running build running build_py creating build creating build\lib.win-amd64-3.7 copying _mysql_exceptions.py -> build\lib.win-amd64-3.7 creating build\lib.win-amd64-3.7\MySQLdb copying MySQLdb__init__.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb creating build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants running build_ext building '_mysql' extension creating build\temp.win-amd64-3.7 creating build\temp.win-amd64-3.7\Release C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include -IC:\Applicazioni_Tommaso\Anaconda3\envs\met3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release_mysql.obj /Zl _mysql.c _mysql.c(42): fatal error C1083: Non è possibile aprire il file inclusione: 'config-win.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2 ---------------------------------------- ERROR: Command "'C:\Applicazioni_Tommaso\Anaconda3\envs\met3\python.exe' -u -c 'import setuptools, tokenize;文件 ='“'”'C:\ Users \ Tommaso \ AppData \ Local \ Temp \ pip-install-yr8h0ec1 \ mysql-python \ setup.py'“'''; f = getattr(tokenize,'”'“' open'“'”',open)(file); code = f.read()。replace('“'”'\ r \ n'“'”,'“'”'\ n'“'”' ); f.close(); exec(compile(code,file,'“'”'exec'“'”')))'安装-记录'C:\ Users \ Tommaso \ AppData \ Local \ Temp \ pip- record-dwqliwhp \ install-record.txt'--single-version-externally-managed --compile“在C:\ Users \ Tommaso \ AppData \ Local \ Temp \ pip-install-yr8h0ec1 \ mysql-中失败,错误代码为1 anaconda \

查看更多

查看更多

提问者
Tms91
被浏览
90
Tms91 2019-07-11 16:22

解决了

在修复了我在上一个答案中描述的问题之后,我发现Heroku在管理mysql数据库方面存在一些问题,即使与附加的ClearDB连接也是如此。因此,我在Postgresql中重建了数据库,因此不再需要mysql python模块。这使我不再迷恋Django和Heroku之间的先前冲突。

发布
问题

分享
好友

手机
浏览

扫码手机浏览