Python mysql.connector connect to DB in specific directory xampp

654 views Asked by At

I have an XAMPP DB I am trying to connect to with mysql.connector on a Red Hat Linux server. The issue is the DB is only accessible from /opt/lampp/bin/mysql. I cannot find a way to specify path with the mysql.connector module.

My code is:

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

Right now I am getting an error when running it mysql.connector.errors.InterfaceError: Failed parsing handshake; end byte not present in buffer but I am assuming that it is probably because I am not specifying path to database.

Thanks

1

There are 1 answers

0
panofish On

I am finding evidence which suggests that this problem is related to MySQL version 5.5.8. What version of MySQL are you running?