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'
)