本文介绍了如何将Azure SQL数据库与Azure Databricks连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Azure SQL数据库与Azure Databricks连接.没有选择.什么是连接技术.任何人都可以帮助我.非常感谢.

I want to connect Azure SQL Database with Azure Databricks. There is no option given. Whats the technique for connectivity. Anyone can help me. Much appreciated.

推荐答案

使用SQL Server身份验证和火花连接器尝试以下代码:

Using SQL Server authentication and the Spark connector try the following code:

val config = Config(Map(
  "url"            -> "kkk-server.database.windows.net:1433",
  "databaseName"   -> "MyDatabase",
  "dbTable"        -> "dbo.Clients",
  "user"           -> "login",
  "password"       -> "xxxxxxxx",
  "connectTimeout" -> "5", //seconds
  "queryTimeout"   -> "5"  //seconds
))

使用Active Directory身份验证,您可以尝试以下代码:

Using Active Directory Authentication you can try code below:

import com.microsoft.azure.sqldb.spark.config.Config
import com.microsoft.azure.sqldb.spark.connect._

val config = Config(Map(
  "url"            -> "kkk-server.database.windows.net:1433",
  "databaseName"   -> "MyDatabase",
  "dbTable"        -> "dbo.Clients",
  "user"           -> "AD-account",
  "password"       -> "xxxxxxxx",
  "connectTimeout" -> "5", //seconds
  "queryTimeout"   -> "5"  //seconds
))

val collection = spark.read.sqlDB(config)
collection.show()

如果您对使用令牌进行AD身份验证感兴趣,请访问这篇文章.

If you are interested in AD authentication using a token, please visit this article.

如果您使用的是Python和Azure Databricks,请尝试使用 JDBC :

If you are using Python and Azure Databricks, try below code with JDBC:

jdbcHostname = "xxxxxxx.database.windows.net"
jdbcDatabase = "yyyyyy"
jdbcPort = 1433
#jdbcUrl = "jdbc:sqlserver://{0}:{1};database={2};user={3};password={4}".format(jdbcHostname, jdbcPort, jdbcDatabase, username, password)

jdbcUrl = "jdbc:sqlserver://{0}:{1};database={2}".format(jdbcHostname, jdbcPort, jdbcDatabase)
connectionProperties = {
  "user" : jdbcUsername,
  "password" : jdbcPassword,
  "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}

pushdown_query = "(INSERT INTO test (a, b) VALUES ('val_a', 'val_b')) insert_test"

教程对于使用JDBC连接到数据库可能很有用.

This tutorial may be useful to connect to a database using JDBC.

这篇关于如何将Azure SQL数据库与Azure Databricks连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:42
查看更多