0

I'm using MySQLdb for python, and I would like to connect to a database hosted on an other PC on the same network/LAN.
I tried the followings for host:

192.168.5.37  
192.168.5.37:3306  
http://192.168.5.37
http://192.168.5.37:3306

None of the above work, I always get the

2005, Unknown MySQL server host ... (0)

What might be the problem?

Code:

db = MySQLdb.connect(host="192.168.5.37", user = "root" passwd = "password", db = "test1")
Fe Ri
  • 195
  • 1
  • 1
  • 9

2 Answers2

0

You can use MySQL Connector/Python, a standardized database driver for Python.
You must provide username, password, host, database name.

import mysql.connector

conn = mysql.connector.connect(user=username, password=password,
                          host="192.168.5.37",
                          database=databaseName)
conn.close()

You can download it from: https://dev.mysql.com/downloads/connector/python/

Kenly
  • 24,317
  • 7
  • 44
  • 60
-1

The IP you posted are local IPs Give it a try with your external IP (for example on this website) https://www.whatismyip.com/

If it works with the external IP, then it's maybe a misconfiguration of your firewall.

Germain
  • 658
  • 7
  • 19
  • Not helpful at all. He said the machines are on the same network. Also, a "local IP" would be 127.0.0.1. – waka Nov 19 '15 at 14:02