Connection code:

db = pymysql.connect("","root","","the-data-base")


Traceback (most recent call last):
  File "adc.py", line 17, in <module>
    db = pymysql.connect("","root","","the-data-base")
  File "/home/pi/.local/lib/python2.7/site-packages/pymysql/__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "/home/pi/.local/lib/python2.7/site-packages/pymysql/connections.py", line 699, in __init__
  File "/home/pi/.local/lib/python2.7/site-packages/pymysql/connections.py", line 967, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '' ([Errno -2] Name or service not known)")
  • Are you sure that firewalls on both computers are allowing the port?
    – Vincent P
    Jul 12, 2018 at 15:41

1 Answer 1


How is port specified on "connect()" method? Is it a separate parameter?

Anyway, the usual flow is:

  • Can both computers see each other (pinging each other is a good way to know).
  • Is the mysql service open for remote connections? If your PC server is a linux box, when you can run this command to know: netstat -lntp. Check for the address associated with port 5901. If it's only then connections to mysql server are only allowed from localhost.
  • If it's open to any host, then is there a firewall running on the server that is rejecting this connections? Again, if the server is a linux box, you can check firewall setup with this command: iptables -L -nv.
  • If everything looks fine on those fronts, then the next question would be: When you use the application, is there a connection plus associated traffic going on? For this you can use a sniffer on any of the two hosts (wireshark, tshark).

That's a good starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.