简体   繁体   English

您可以连接到另一台PC上的数据库吗?

[英]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.

相关问题 如何使用python将树莓派连接到另一台PC的数据库 - How to connect raspberry pi to another PC's database using python 我可以连接到另一台服务器上的mysql数据库吗? - Can I connect to a mysql database on another server? 我们可以连接到Django另一台主机上的其他数据库吗 - Can we connect to other database on another host in django 如何使用 pyodbc 在另一台电脑上连接到 Microsft SQL Sever 2005? - How to connect to Microsft SQL Sever 2005 in another pc using pyodbc? 如果不提供 Python 代码中的纯凭据,您能否连接到 MySQL 数据库? - Can you connect to MySQL database without providing pure credentials in Python code? 在服务器上安装 postgresql 数据库并在另一个 pc 客户端上运行 gui 应用程序 - install postgresql database on server and run gui application on another pc client 启用端口转发后,无法访问另一台PC上的MySQL数据库 - Unable to access MySQL Database on another PC with port forwarding on 什么样的Android框架可用于将PC连接到Android和Android到其他PC? - What framework of Android can be used to connect PC to Android and Android to other PC? 我已经创建了1台服务器,该服务器可以将一台客户端连接到另一台PC上,并将另一台客户端连接为Localhost? - I have created 1 server which connect one client in another PC and another one as Localhost? 如何将运行 python 程序的 pod 与另一个运行数据库的 pod 连接起来 - How can I connect a pod which runs a python program with another pod which runs a database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM