Not able to connect to SSL enable Azure MySql using python script.

Mahendra Rajgude 20 Reputation points
2025-03-13T04:24:54.98+00:00

not able to connect to SSL enable Azure MySql using python script.

Getting following error in Python

mysql.connector.errors.InterfaceError: 2055: Lost connection to MySQL server at 'gcm-daas-backup-srv.mysql.database.azure.com:3306', system error: 1 [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:1002)

Any help / pointer will appreciated.

Mahendra

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

Accepted answer
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2025-03-13T11:04:59.8133333+00:00

    Hello Mahendra,

    Verify if you have the necessary Python packages installed. You need mysql-connector-python and cryptography for SSL support.

    
    pip install mysql-connector-python cryptography
    

    Azure MySQL requires an SSL certificate to establish a secure connection. You can download the DigiCert Global Root CA certificate from here.

    Example to help you configure SSL in your Python script:

    
    import mysql.connector
    
    from mysql.connector import Error
    
    try:
    
        # Path to the SSL certificate
    
        ssl_ca = '/path/to/DigiCertGlobalRootCA.crt'
    
        # Establish the connection
    
        connection = mysql.connector.connect(
    
            host='gcm-daas-backup-srv.mysql.database.azure.com',
    
            user='your_username',
    
            password='your_password',
    
            database='your_database',
    
            port=3306,
    
            ssl_ca=ssl_ca,
    
            ssl_verify_cert=True
    
        )
    
        if connection.is_connected():
    
            cursor = connection.cursor()
    
            cursor.execute("SELECT VERSION()")
    
            db_version = cursor.fetchone()
    
            print("Database version:", db_version)
    
    except Error as e:
    
        print("Error while connecting to MySQL", e)
    
    finally:
    
        if connection.is_connected():
    
            cursor.close()
    
            connection.close()
    
            print("MySQL connection is closed")
    

    If you need to specify custom cipher suites, you can do so by adding the ssl_cipher parameter:

    
    connection = mysql.connector.connect(
    
        host='gcm-daas-backup-srv.mysql.database.azure.com',
    
        user='your_username',
    
        password='your_password',
    
        database='your_database',
    
        port=3306,
    
        ssl_ca=ssl_ca,
    
        ssl_verify_cert=True,
    
        ssl_cipher='DHE-RSA-AES256-SHA:AES128-SHA'
    
    )
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Mahendra Rajgude 20 Reputation points
    2025-03-15T03:02:39.6433333+00:00

    Thanks for help.

    Basically , our problem got solved after uninstalling and installing sql packages in python, clearing cache and deleting temp files.

    Thanks for your help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.