skip to Main Content

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


  1. Here are few things you should check , if it doesn’t after doing all this , please let us know

    1. mysql yourdomain.com 3306 , check this to make sure port 3306 works.
    2. Check if your firewall blocking access
    3. check your mysql config is set to accept remote connections
    Login or Signup to reply.
  2. Could you please try following command and see if it is connecting or not?

    mysql -h your_remote_host -u your_user -p
    
    telnet your_remote_host 3306
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search