skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. If your organization’s computer is connected to a domain, it may be assigned a Fully Qualified Domain Name (FQDN). In this case, "localhost" may not work as expected.

    Check with hostname command and verify.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search