Connection reset by peer - MySQL and Python

Scott Fergusson 1 Reputation point
2020-09-28T18:00:31.027+00:00

Hello - I am building an application that:

  1. Parses a CSV with item numbers.
  2. Hits our Azure mySQL to see if the item exists
  3. If it does, it goes to the next item
  4. If it doesn't, it adds the item to the database.

The CSV has thousands of items. I run this application on a Mac (Catalina), with Python 3.8.2 Without fail, the python code fails with an [Errno 54] Connection reset by peer when I've parsed through 294 items.

When I ran it on a Win10 PC, I got a 'connection forcibly closed' error. It looks like some sort of block or limit is being hit. Any ideas?

Here's the actual error line:

mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'appdb.mysql.database.azure.com:3306', system error: 54 Connection reset by peer

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

1 answer

Sort by: Most helpful
  1. Mike Ubezzi 2,776 Reputation points
    2020-09-30T23:51:51.93+00:00

    Thank you for confirming the issue as from either host, @Scott Fergusson . There are two steps to work towards resolving this issue and they include:

    1. Enable redirect on your Azure Database for MySQL instance. This will bypass the gateway host in the region for which your service is deployed, after authentication has been established. All client <> server traffic is direct without a gateway serving the requests. Please see: Connect to Azure Database for MySQL with redirection
    2. The second item is leveraging Azure Monitor for data platform to either: a) further troubleshoot connectivity issues, or b) identify incremental gains at the query level through Query Performance Insight (Applies to: Azure Database for MySQL 5.7, 8.0).