Search code examples
pythonsqllocalhostconnection-refused

mysql.connector.errors.interfaceerror 2003


My summer project is to put data into SQL for processing. Unfortunately I can not establish a connection to the SQL with mysql connector.

The python file I am testing with are two lines: import mysql.connector

db1 = mysql.connector.connect(host="localhost", database="thename", user="user",password="passw")

The error message is:

C:\Projekt\Python efforts...>test.py Traceback (most recent call last): File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\network.py", line 472, in open_connection self.sock.connect(sockaddr) ConnectionRefusedError: [WinError 10061] Det gick inte att göra en anslutning eftersom måldatorn aktivt nekade det

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Projekt\Python efforts...\test.py", line 4, in db1 = mysql.connector.connect(host="localhost", database="thename", user="user",password="passw") File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector__init__.py", line 179, in connect return MySQLConnection(*args, **kwargs) File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\connection.py", line 95, in init self.connect(**kwargs) File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\abstracts.py", line 719, in connect self._open_connection() File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection self._socket.open_connection() File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\network.py", line 475, in open_connection errno=2003, values=(self.get_address(), _strioerror(err))) mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 Det gick inte att göra en anslutning eftersom måldatorn aktivt nekade det)

C:\Projekt\Python efforts...>

I have tried restarting and enabling services and computer several times. The user and password I use grants me access in SQL Server Management Studio. I have created a firewall rule to allow communication on port 3306, though it is not listed as one of the active ports when I look. I have also tried disabling the firewall on my computer (though not on the router as it should not be needed for a localhost query?). Using wireshark I don't seem to get any traffic at all on port 3306(!?). I cannot telnet to localhost though tracert has no problems. I have tried with different IPs and domain name that are valid. I have enabled TCP/IP settings for a bunch of the different IP versions under TCP/IP protocol in the SQL Server Configuration manager (though I'm not sure how I did that as it is write protected so I can't do the rest of them).

Everything listed here yields the same result so I assume that there is something very fundamentally (basic and easy?) wrong with what i am doing. Please pitch in with any and all troubleshooting tips you can find for resolving this connection issue as I am on my third day of getting absolutely nowhere.


Solution

  • Once again it has been proven that it is easy to get blinded when digging. I was trying to use mysql connector to connect to a ms sql. I have now switched to pypyodbc to handle the communication with the SQL.