写入 SQL Server
使用 Flux 将数据写入 Microsoft SQL Server:
导入
sql包。将数据通过管道传递到
sql.to()并提供以下参数:- driverName: sqlserver
- dataSourceName: 查看数据源名称
- table: 要写入的表
- batchSize: 每次调用
Exec时可以排队的参数或列的数量(默认为10000)
import "sql"
data
|> sql.to(
driverName: "sqlserver",
dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
table: "Example.Table",
)
SQL Server 数据源名称
根据连接字符串,sqlserver 驱动程序使用以下 DSN 语法:
sqlserver://username:password@localhost:1433?database=examplebdb
server=localhost;user id=username;database=examplebdb;
server=localhost;user id=username;database=examplebdb;azure auth=ENV
server=localhost;user id=username;database=examplebdbr;azure tenant id=77e7d537;azure client id=58879ce8;azure client secret=0143356789
SQL Server ADO 认证
使用以下方法之一来提供 SQL Server 认证凭据作为 ActiveX 数据对象 (ADO) DSN 参数:
从环境变量中检索认证凭据
azure auth=ENV
从文件中获取身份验证凭据
InfluxDB Cloud 和 InfluxDB OSS 不 可以访问 底层文件系统,并且不支持从文件中读取凭据。 要从文件中检索 SQL Server 凭据,请在你的本地计算机上执行查询 Flux REPL。
azure auth=C:\secure\azure.auth
在DSN中指定身份验证凭据
# Example of providing tenant ID, client ID, and client secret token
azure tenant id=77...;azure client id=58...;azure client secret=0cf123..
# Example of providing tenant ID, client ID, certificate path and certificate password
azure tenant id=77...;azure client id=58...;azure certificate path=C:\secure\...;azure certificate password=xY...
# Example of providing tenant ID, client ID, and Azure username and password
azure tenant id=77...;azure client id=58...;azure username=some@myorg;azure password=a1...
在Azure虚拟机中使用托管标识
有关托管身份的信息,请参阅 Microsoft managed identities。
azure auth=MSI
Flux 到 SQL Server 数据类型转换
sql.to() 将Flux数据类型转换为SQL Server数据类型。
| Flux 数据类型 | SQL Server 数据类型 |
|---|---|
| float | 浮点数 |
| int | 大整数 |
| uint | 大整数 |
| 字符串 | VARCHAR(MAX |
| 布尔值 | 位 |
| 时间 | DATETIMEOFFSET |