共用方式為


使用 Azure Databricks 查詢 MariaDB

此範例會使用其 JDBC 驅動程式查詢 MariaDB。 如需讀取、寫入、設定平行處理原則和查詢下推的詳細資訊,請參閱 使用 JDBC 查詢資料庫。

建立 JDBC URL

Python

driver = "org.mariadb.jdbc.Driver"

database_host = "<database-host-url>"
database_port = "3306" # update if you use a non-default port
database_name = "<database-name>"
table = "<table-name>"
user = "<username>"
password = "<password>"

url = f"jdbc:mariadb://{database_host}:{database_port}/{database_name}"

Scala

val driver = "org.mariadb.jdbc.Driver"

val database_host = "<database-host-url>"
val database_port = "3306" # update if you use a non-default port
val database_name = "<database-name>"
val table = "<table-name>"
val user = "<username>"
val password = "<password>"

val url = s"jdbc:mariadb://${database_host}:${database_port}/${database_name}"

查詢遠端資料表

Python

remote_table = (spark.read
  .format("jdbc")
  .option("driver", driver)
  .option("url", url)
  .option("dbtable", table)
  .option("user", user)
  .option("password", password)
  .load()
)

Scala

val remote_table = spark.read
  .format("jdbc")
  .option("driver", driver)
  .option("url", url)
  .option("dbtable", table)
  .option("user", user)
  .option("password", password)
  .load()