首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python mysql.connector连接到特定目录xampp中的DB

问Python mysql.connector连接到特定目录xampp中的DB
EN

Stack Overflow用户
提问于 2014-11-18 00:48:07
回答 1查看 557关注 0票数 0

我有一个XAMPP DB,我正试图通过Red Hat Linux服务器上的mysql.connector连接到它。问题是数据库只能从/opt/lampp/bin/mysql访问。我找不到使用mysql.connector模块指定路径的方法。

我的代码是:

代码语言:javascript
复制
import mysql.connector


config = {
  'user': 'user',
  'password': '*****',
  'host': '127.0.0.1',
  'database': 'test',
  'raise_on_warnings': True,
}

cnx = mysql.connector.connect(**config)

cursor = cnx.cursor()

query = "show columns from Table1"

cursor.execute(query)

lst = []
for line in cursor:
    lst.append(line[0])

query2 = "select * from Table1 limit 5"

lst2 = []

cursor.execute(query2)

for line in cursor:
    lst2.append(dict(zip(lst, line)))

print(lst2)

cnx.close()

现在,我在运行mysql.connector.errors.InterfaceError: Failed parsing handshake; end byte not present in buffer时收到一个错误,但我假设这可能是因为我没有指定数据库的路径。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-12-03 22:40:58

我正在寻找证据表明这个问题与MySQL版本5.5.8有关。您运行的是什么版本的MySQL?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26977618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档