0

I´m trying to connect to an Azure Mysql database server to create a table from a Dataframe in Azure Synapse with Spark.

I have this url and this properties All variables like jdbcXYZ are fulled with the correct values from the database


import java.util.Properties


val jdbc_url = s"jdbc:mysql://${jdbcHostname}:${jdbcPort}/database=${jdbcDatabase};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=60;"
val connectionProperties = new Properties()
connectionProperties.put("user", s"${jdbcUsername}")
connectionProperties.put("password", s"${jdbcPassword}")


And i try to write to the database with

spark.table("tabletemp").write.mode("append").jdbc(jdbc_url, "table", connectionProperties)

I also tried

df.write.format("jdbc").mode("append").option("url", jdbc_url).option("dbtable", jdbcDatabase).option("user", jdbcUsername).option("password", jdbcPassword).save()

And i´m always receiving the same error

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server


Do you know how to solve it? Thanks in advance

Jose
  • 25
  • 1
  • 5

1 Answers1

0

I am very confident that this a config issue , you are not passing all correct value for all the properties . I quick scan makes me think that this is not correct .

.option("dbtable", jdbcDatabase).

HimanshuSinha
  • 1,650
  • 2
  • 6
  • 10
  • Hi, First thanks for your reply. I took that line from spark docs: spark.apache.org/docs/latest/sql-data-sources-jdbc.html where it puts that option. Thanks! – Jose Nov 15 '22 at 08:20