Python My SQL connection

Jack Brien 0 Reputation points
2023-05-16T18:27:48.09+00:00

Hello,

Hoping someone can help me with a connection issue. I'm trying to connect a python script to a mysql database using the mysql.connector library, but it keeps throwing an error. (2003 (HY000): Can't connect to MySQL server on 'example.database.windows.net:3306' (10060))

I've got the host set to (server name swapped out for "example") "example.database.windows.net", and have also tried "example.mysql.database.windows.net", neither of which work, and neither of which can I resolve with DNS using my ISP, 8.8.8.8 or 1.1.1.1.

When I have eventually found a DNS record for this (51.105.72.32), this IP is not pingable.

Please can someone correct my syntax or point me in the direction of how to fix this?

Thanks,

Jack

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
712 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Konstantinos Passadis 17,286 Reputation points
    2023-05-16T18:47:37.1166667+00:00

    Hello @Jack Brien!

    Welcome to Microsoft QnA!

    I understand you want to connect from your Local PC to Azure MySql

    First of all avoid exposing IPs and Credentials , try somehting like XX.XX.XX.XX, not everyone has the best intentions!

    Please go to Azure Portal and add your IP address to the allowed list :

    User's image

    If you are on Public Hotspot make a try to add all nets and see if you can connect

    If you cannot , there is a chance your Outbound Access i restricted in 3306

    MySQL is not Pingable btw

    Check also this :

    User's image

    In case SSL is set to required you need to follow these

    https://learn.microsoft.com/en-us/azure/mysql/single-server/how-to-configure-ssl

    So you can get the Certificate

    Please go carefully through the Docs!

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


  2. GeethaThatipatri-MSFT 27,102 Reputation points Microsoft Employee
    2023-05-18T22:52:17.9733333+00:00

    @Jack Brien Here are the clear steps you can follow https://stackoverflow.com/questions/39461850/connecting-to-azure-sql-with-python

    If you are still facing the issue please provide more details to better assist you.

    Regards

    Geetha