itsayushbansal itsayushbansal - 1 year ago 72
SQL Question

I am unable to establish connection with mySQL

my code

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


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

Answer Source

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='', `database='testdb')