0

Source code:

import mysql.connector

from mysql.connector import errorcode
try:
    cnx = mysql.connector.connect(user='root',database='menagerie')
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Something is wrong with your user name or password")
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print("Database does not exist")
    else:
        print(err)
else:
    cnx.close()

The error I am facing: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (10061 No connection could be made because the target machine actively refused it)

Moin
  • 117
  • 1
  • 5

1 Answers1

0
import mysql.connector
cnx=mysql.connector.connect(user="root",host="localhost",passwd="*******",database="menagerie")

The above code establishes the connection to MySql.

saurabh sisodia
  • 312
  • 1
  • 8