Reputation: 1556
I created a new Windows 11 VM with mySQL and PyCharm installed. To test connectivity from Python to mySQL, I created the following program.
print('Start mySQL Query test')
import mysql.connector
print('Test')
cnx = mysql.connector.connect(user='python', password='password!', host='127.0.0.1', database='mes_core')
print('Test2') # This never gets printed because the connect call crashes
try:
cursor = cnx.cursor()
cursor.execute('select * from enterprise')
result = cursor.fetchall()
print(f'result={result}')
finally:
cnx.close()
The call to connect crashes with error message:
Process finished with exit code -1073741819 (0xC0000005)
Exit code 0xC0000005 is an Access Violation error but I cannot figure out why I would get this error in a clean VM with little more than mySQL and PyCharm installed.
Versions:
I tried to debug this with the following code. Unfortunately, even though the connect is enclosed in a try, it still traps in the connect call and none of the prints that follow are output.
import mysql.connector
from mysql.connector import errorcode
try:
print('About to connect')
cnx = mysql.connector.connect(user='python',
password='Bootcamp',
host='127.0.0.1',
database='mes_core')
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
print('Success')
cnx.close()
Output:
About to connect
Process finished with exit code -1073741819 (0xC0000005)**
Upvotes: 0
Views: 76
Reputation: 1556
I went into the Windows Event viewer and looked at application logs. Here is what it said. Faulting application name: python.exe, version: 3.13.1150.1013, in DLL SVCP140.dll.
The issue turned out to be that the C distribution package was missing because this was a fresh windows VM, and I needed to install the Microsoft Visual C++ Redistributable package that includes the C distribution.
Once this was installed, I restarted the VM and the code worked correctly!
Note that I previously created the following test code to catch the error to the mySQL mysql.connector.connect call as an Exception. However the code continued to trap deep within Windows (below Python) with an Exception code: 0xc0000005.
Because the crash occurred within the Windows OS DLL executable, it could not return to the Python run time environment and so python could not catch
the exception and report it.
import mysql.connector
from mysql.connector import errorcode
try:
print('About to connect')
cnx = mysql.connector.connect(user='python',
password='Bootcamp!',
host='127.0.0.1',
port=3306)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
except Exception as err:
# This except clause does NOT get invoked
print(f'System error: {err}')
else:
print('Success')
cnx.close()
Once the MS C/C++ distributable was loaded and the operating system restarted, this code worked and printed Success
.
Upvotes: 0
Reputation: 1
check version compatibility check whether MYSQL is running or not specify the port where it is running.
Upvotes: 0