Why is Python 3.5 crashing on a MySQL connection with correct credentials?
<p>I'm using Python 3.5.1, mysqlclient 1.3.9 (fork of MySQLdb that supports Python 3), and MariaDB 10.1 on Windows 10 (64-bit).</p>

<p>When I run</p>

<pre><code>import MySQLdb
con = MySQLdb.connect(user=my_user, passwd=my_pass, db=my_db)
</code></pre>

<p>Python crashes.</p>

<p>In pycharm, I am also presented with the message</p>

<pre><code>Process finished with exit code -1073741819 (0xC0000005)
</code></pre>

<p>I don't get any other errors. This is different to what happens when I run the same statements with incorrect credentials:</p>

<pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Program Files\Python35\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Program Files\Python35\lib\site-packages\MySQLdb\connections.py", line 191, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
</code></pre>

<p>This error does not occur on my CentOS server, which runs Python 3.4, mysqlclient 1.3.9, and MariaDB 10.1.</p>

<p>I've tried using older versions of MariaDB as suggested by <a href="http://stackoverflow.com/questions/35572662/django-runserver-stuck-on-performing-system-checks">this question</a>, to no avail.</p>

<p>What could be causing this crash and the mysterious lack of error reporting, and how can I fix it?</p>

<p>Edit: In my system logs, I found this entry:</p>

<p>General:</p>

<pre><code>Faulting application name: python.exe, version: 3.5.1150.1013, time stamp: 0x56639598
Faulting module name: python35.dll, version: 3.5.1150.1013, time stamp: 0x56639583
Exception code: 0xc0000005
Fault offset: 0x00000000000e571c
Faulting process id: 0x4a4
Faulting application start time: 0x01d2272a22ae1a1a
Faulting application path: C:\Program Files\Python35\python.exe
Faulting module path: C:\Program Files\Python35\python35.dll
Report Id: 6dd874e6-5ea5-4919-af8b-4880a2c7ac5e
Faulting package full name: 
Faulting package-relative application ID: 
</code></pre>

<p>Details: </p>

<pre><code>- System 
  - Provider 
   [ Name]  Application Error 
  - EventID 1000 
   [ Qualifiers]  0 
   Level 2 
   Task 100 
   Keywords 0x80000000000000 
  - TimeCreated 
   [ SystemTime]  2016-10-15T21:21:48.041795500Z 
   EventRecordID 7615 
   Channel Application 
   Computer PETER-LENOVO 
   Security 

- EventData 
   python.exe 
   3.5.1150.1013 
   56639598 
   python35.dll 
   3.5.1150.1013 
   56639583 
   c0000005 
   00000000000e571c 
   4a4 
   01d2272a22ae1a1a 
   C:\Program Files\Python35\python.exe 
   C:\Program Files\Python35\python35.dll 
   6dd874e6-5ea5-4919-af8b-4880a2c7ac5e
</code></pre>

<p>I'm not familiar with <code>pycharm</code> but I think your problem is as @nemanjap suggests, with your <code>MySQLdb</code> installation. I just went through a similar nightmare (with Python 3.5), so I hope I can help. Here are my suggestions:</p>

<ul>
<li>If you haven't already, install <code>pip</code></li>
<li>Install Visual Studio Community 2015 from <a href="https://www.visualstudio.com/downloads" rel="nofollow">https://www.visualstudio.com/downloads</a> (you only need the Python compilation tools)</li>
<li>Install wheel: <code>pip install wheel</code></li>
<li>Download the MySQLdb windows binary from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python</a>, specifically <code>mysqlclient-1.3.8-cp35-cp35m-win32.whl</code> (I'm 64-bit too, but I was being cautious)</li>
<li>Delete the MySQLdb folder from site-packages if it exists, just in case.</li>
<li>Assuming you're in the same folder as the binary download, run <code>pip install mysqlclient-1.3.8-cp35-cp35m-win32.whl</code></li>
</ul>

<p>With a bit of luck, you should be able to connect.</p>

<hr>

<p><strong>Notes</strong></p>

<p>On my machine, I was getting instantly aborted connections (<code>Got an error reading communication packets</code> in my <code>error.log</code>), even though my credentials were 100% correct. On the windows side, similar to OP, Python just "crashed", meaning I got a shell restart and never reaching past the <code>MySQLdb.connect</code> line. Even a <code>try</code> block didn't allow further execution (so actually a crash, as opposed to an exception or error). Thinking a compatibility issue (UNIX working totally fine), I tried to debug the <code>MySQLdb</code> in Windows, all the way to <code>import _mysql</code>, which is when I realized it was a C (compilation) issue.</p>

<p>Having thought all was installed well, when I executed <code>pip install MySQLdb-python</code>, I got the following:</p>

<pre><code>error: Unable to find vcvarsall.bat
</code></pre>

<p>Which meant I needed to install the compilation tools for my version of Python (3.5), which is included in the VSC2015 installation. I re-ran, and then got the following:</p>

<pre><code>Cannot open include file: 'config-win.h'
</code></pre>

<p>Which meant I needed some required headers, from here: <a href="http://dev.mysql.com/downloads/connector/c/6.0.html#downloads" rel="nofollow">http://dev.mysql.com/downloads/connector/c/6.0.html#downloads</a> (again, 32-bit, just to play it safe for now). Then I got a bunch of <code>unresolved external symbol</code> errors, and realized how much I hate Windows, and installed the pre-compiled version instead. Worked wonders.</p>

<p>Oh, and before someone suggests a different module or method to connect, like <code>mysql-connector</code>, apart from not solving the problem, there is usually the constraint that the same code (thus, the same imported modules) should work on both Windows and UNIX machines. Plus this: <a href="http://charlesnagy.info/it/python/python-mysqldb-vs-mysql-connector-query-performance" rel="nofollow">http://charlesnagy.info/it/python/python-mysqldb-vs-mysql-connector-query-performance</a></p>

<p>Sorry for the long post. I needed to vent! Good luck!</p>

python mysql python-3.x mariadb