Python error connecting to Azure MySQL

SC-2022 1 Reputation point
2022-01-17T13:21:11.177+00:00

I have setup Azure MySQL 5.3 Flexible along with setting up my IP to access. I created a connection from MySQL workbench and was able to create a table. When trying to connect via my Python script from my local machine i keep getting the below error. I have Python version 3.10.0 installed. I followed the Microsoft steps to connect but still no luck.

2003: Can't connect to MySQL server on '%-.100s:%u' (%s) (Warning: %u format: a real number is required, not str)

Steps followed:

https://learn.microsoft.com/en-us/azure/mysql/connect-python
connect-python

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
714 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 27,642 Reputation points Microsoft Employee
    2022-01-17T20:57:10.903+00:00

    Hi, @SC-2022 Welcome to Microsoft Q&A, Thanks for posting your question.
    I Understand that you are unable to connect to PostgreSQL using Python using the script/sample code from the document.
    I tried to connect using the above-mentioned code from the document and i was able to connect successfully please check the below code which might help you to fix if you have any issues in your code as the error seems to be in the code, also I want to check if you have followed all the prerequisites.

    165766-image.png

    165796-image.png

    Regards
    Geetha