Warm tip: This article is reproduced from stackoverflow.com, please click
django mysql python

django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading ini

发布于 2020-03-27 10:27:47

I am developing an app in django to push it on Heroku, and while trying to migrate a database in mysql to heroku, I pip installed mysql-python and as I try to run the server, I got this error:

django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 0")

(I had my virtual environment on).
The strange thing is that the package installed python even if I had that already installed.
I found out that it unistalled django and several modules I previously installed, even pip!

I re-installed the modules but now as I run the server I get that error above.
If I run the server from another app directory, the database runs fine.
Is it maybe related to something I had installed in my directory and maybe was apparently overwritten by the strange package?

here is my pip freeze result:

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>

I will now delete the project and try to rebuild it anew, as long as I understand, what screw up the project was my attempt to install 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;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" failed with error code 1 in C:\Users\Tommaso\AppData\Local\Temp\pip-install-yr8h0ec1\mysql-python\

Questioner
Tms91
Viewed
239
Tms91 2019-07-11 16:22

Solved

After fixing thing as I decribed in the previous answer , I found out that Heroku has some problems to manage mysql database, even if connected with the add-on ClearDB. So I rebuilt the database in Postgresql, thus not needing the mysql python modules anymore. This made me not stumble anymore in the previous conflicts between Django and Heroku.