你能连接到另一台电脑上的数据库吗? [英] Can you connect to a database on another pc?

查看:57
本文介绍了你能连接到另一台电脑上的数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 MySQLdb 用于 Python,并且我想连接到同一网络/LAN 上另一台 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.
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, 未知 MySQL 服务器主机 ... (0)

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

可能是什么问题?

代码:

db = MySQLdb.connect(host="192.168.5.37", user = "root" passwd = "password", db = "test1")

推荐答案

您可以使用 MySQL Connector/Python,这是 Python 的标准化数据库驱动程序.
您必须提供用户名、密码、主机、数据库名称.

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()

您可以从以下位置下载:https://dev.mysql.com/downloads/connector/蟒蛇/

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

这篇关于你能连接到另一台电脑上的数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆