I am trying to connect to a MySQL database hosted on my website’s domain using Python, but I keep encountering the following error:
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to
MySQL server on 'localhost:3306' (10061)
my code:
import mysql.connector
try:
db = mysql.connector.connect(
host="", # My database in not on localhost so here i put my websites domain name and the rest of the creditials
user="",
password="",
database=""
)
print("Connection successful!")
except mysql.connector.Error as err:
print(f"Error: {err}")
I have verified the credentials and checked that the database is accessible from a remote host by adding my IP to the "Add Remote MySQL Host" list in my web hosting control panel
but i still get the error message.Is there any special configuration needed for connecting to remote MySQL databases on hosting services?
2
Answers
Here are few things you should check , if it doesn’t after doing all this , please let us know
Could you please try following command and see if it is connecting or not?
Above command will help you to verify the connection from your machine.
Could you please paste error as well? that will help with getting more details on issue.