Azure Mysql服务器与Azure Synpase Spark连接不工作



我正在尝试连接到Azure Mysql数据库服务器,使用Spark从Azure Synapse中的Dataframe创建一个表。

我有这个url和属性像jdbcXYZ这样的所有变量都充满了来自数据库

的正确值。

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}")

我试着用

写数据库
spark.table("tabletemp").write.mode("append").jdbc(jdbc_url, "table", connectionProperties)

我也试过

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

我总是收到相同的错误

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

你知道怎么解它吗?提前感谢

我非常确信这是一个配置问题,您没有为所有属性传递所有正确的值。我快速扫描了一下,觉得这是不对的。

.option("dbtable"jdbcDatabase)。

最新更新