[英]Can you connect to a database on another pc?
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. 我将MySQLdb用于python,我想连接到同一网络/ LAN上另一台PC上托管的数据库。
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)
2005,未知的MySQL服务器主机...(0)
What might be the problem? 可能是什么问题?
Code: 码:
db = MySQLdb.connect(host="192.168.5.37", user = "root" passwd = "password", db = "test1")
You can use MySQL Connector/Python
, a standardized database driver for Python. 您可以使用
MySQL Connector/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/ 您可以从以下网址下载: https : //dev.mysql.com/downloads/connector/python/
The IP you posted are local IPs Give it a try with your external IP (for example on this website) https://www.whatismyip.com/ 您发布的IP是本地IP请尝试使用您的外部IP(例如在此网站上) https://www.whatismyip.com/
If it works with the external IP, then it's maybe a misconfiguration of your firewall. 如果它与外部IP一起使用,则可能是防火墙的配置错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.