Pankaj Garg
Pankaj Garg

Reputation: 49

How to fix 'Can't connect to MySQL server on 'localhost:3306' error

I am trying to connect to the MySQL database with Python. I am running following code

import mysql.connector
from mysql.connector import Error
import pyodbc 

conn = mysql.connector.connect(host='localhost',
                             database='data1',
                             user='username',
                             password='xxxx')

and get the error message

InterfaceError: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)

Upvotes: 2

Views: 2744

Answers (1)

Flash Thunder
Flash Thunder

Reputation: 12036

You are using MySQL driver to connect to MS SQL, which won't work… What you need is something like this:

   import pymssql  
   conn = pymssql.connect(server='localhost', user='username', password='xxxx', database='data1') 

Upvotes: 1

Related Questions