Search code examples
pythonmysqlmysql-connector

python mysql.connector does not throw any error or message, only exit from application


I am trying to connect my localhost mysql server. My personel computer succusfully connect to mysql server with tis python code:

import mysql.connector
from mysql.connector import Error

class DatabaseHelper():
    def __init__(self): 
        self.host = "localhost"
        self.user = "root"
        self.password = "mysql"
        self.database = "temperedglassdb"
        self.db = None
        
    def connectDb(self):
        try:
            print("Started")
            if not self.isConnected():
                self.db = mysql.connector.connect(
                            host = self.host, 
                            user = self.user, 
                            password = self.password, 
                            database = self.database)
            print("Finished")
            print(self.db)
        except Error as e:
            print(e)
        
    def isConnected(self):
        if self.db is not None:
            return self.db.is_connected()
        else:
            return False

if __name__ == "__main__": 
    db = DatabaseHelper()
    db.connectDb()

Prints ->

Started

But on my work computer which has many organizational restriction. I could not connect to localhost mysql server on it. And this code does not throws any warning or error or any message to resolve the issue?

enter image description here

How do i learn which problems is occours?


Solution

  • Actually this happened because of visual studio based error. I tried on different computer and it is working correctly. I assume the visual stuido did not installed properly. After I checked Event Viewer, I saw an MSVCP140.dll error.

    Also I reinstalled vc_redist.x64.exe. It solved for me!