cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

AWS Databricks Pyspark - Unable to connect to Azure MySQL - Shows "SSL Connection is required"

Rexton
New Contributor

Even after specifying SSL options, unable to connect to MySQL. What could have gone wrong? Could anyone experience similar issues?

df_target_master = spark.read.format("jdbc")\

.option("driver", "com.mysql.jdbc.Driver")\

.option("url", host_url)\

.option("dbtable", supply_master)\

.option("user", user_id)\

.option("password", pwd)\

.option("ssl", True) \

.option("sslmode", "verify-ca" ) \

.option("sslrootcert", "<s3 bucket location") \

.load()

3 REPLIES 3

User16764241763
Honored Contributor

@Rexton Das​ 

Can you try disabling below SSL setting on MySQL Azure Database -> Connection Security and see if it connects?

image

User16764241763
Honored Contributor

Or you can try enabling SSL in the URL using &useSSL=true&requireSSL=true

a2barbosa
New Contributor II

Hey,

Here the solution: The correct option for ssl is "useSSL" and not just "ssl".

This code below could works:

df_target_master = spark.read.format("jdbc")\

.option("driver", "com.mysql.jdbc.Driver")\

.option("url", host_url)\

.option("dbtable", supply_master)\

.option("user", user_id)\

.option("password", pwd)\

.option("useSSL", True) \

.option("sslmode", "verify-ca" ) \

.option("sslrootcert", "<s3 bucket location") \

.load()

I'm able to access a mySQL with "Enforce SSL Connection" Enabled in Azure with only this change.

In Databricks Runtime 11.2 and above you can use the MySQL connector in Databricks Runtime. The code could be like this:

remote_table = (spark.read

.format("mysql")

.option("dbtable", table)

.option("host", database_host_url)

.option("port", 3306)

.option("database", database_name)

.option("user", uid)

.option("password", pwd)

.option("useSSL", True)

.option("sslmode", "verify-ca" )

.load()

)

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group