'Python SQL Error: 2003 (HY000): Can't connect to MySQL server on '192.168.1.1:3306' (10061) SSMS

it seems I can't connect to my SQL Server Management Studios (installed on a Win machine) database and I don't know why since some other scheduled Python jobs I personally created that execute other queries work just fine.

This is an example of my code:

import sys
import mysql.connector

try:

  conn = mysql.connector.connect(
      host="192.168.1.1",
      user="sa",
      password="sa",
      database="Test"
  ) 
  cursor = conn.cursor()

  query = "SELECT * FROM [DB] WHERE [Art] = 'EX'"
  cursor.execute(query)
  row = cursor.fetchall()

  if cursor.rowcount == 0:
     print("No results")
     sys.exit()


except Exception as e:

  print(e)

Everytime throws the error 2003 (HY000): Can't connect to MySQL server on '192.168.1.1:3306' (10061)

And yes, I checked if any services were down (like written on other answers I found on the internet) but they all were up

I tried to execute my script on 2 other PCs but it didn't work

I even tried restarting the server and guess what, it didn't work

Thanks in advance



Solution 1:[1]

According to my understanding, you are trying to connect with Microsoft SQL Server Management Studio using Python.

If so, you need pyodbc python module.

To install pyodbc module, open cmd and run the following:

python -m pip install pyodbc

Now, to connect database :

import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
                    'Server=username\SQLEXPRESS;'
                    'Trusted_Connection=yes;')

Replace 'username' with your desktop username

find pyodbc documentation here

also you can follow this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ondhokaar