itsayushbansal itsayushbansal - 4 months ago 10
SQL Question

I am unable to establish connection with mySQL

my code

import MySQLdb
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="root", passwd="xyz", db="testdb")


error:

AttributeError: 'Connection' object has no attribute 'get_autocommit'

Answer

When connecting to a mysql database usually in most languages you would need to have a mysql connector , in this case since you are talking about python programming language this is the way you should've written the connection (this works well with python 5.1 ) i hope it helps! :

import mysql.connector

con = mysql.connector.connect(user='root', password='xyz', host='127.0.0.1', `database='testdb')
Comments