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

时间:2014-11-17 16:48:07

标签: python mysql python-3.x xampp mysql-connector-python

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

我的代码是:

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时遇到错误,但我认为可能是因为我没有指定数据库的路径。

由于

1 个答案:

答案 0 :(得分:0)

我发现有证据表明此问题与MySQL 5.5.8版有关。你在运行什么版本的MySQL?

相关问题