sql 包
sql 包提供了用于在 SQL 数据库中处理数据的工具。导入 sql 包:
import "sql"
SQL 数据源名称
该 sql 包使用 Go 驱动程序连接到 SQL 数据库。数据源名称(DSN)(也称为连接字符串)由所使用的驱动程序确定。
# Amazon Athena Driver DSN
s3://myorgqueryresults/?accessID=AKIAJLO3F...®ion=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F...
s3://myorgqueryresults/?accessID=AKIAJLO3F...&db=dbname&missingAsDefault=false&missingAsEmptyString=false®ion=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F...&WGRemoteCreation=false
# MySQL Driver DSN
username:password@tcp(localhost:3306)/dbname?param=value
# Postgres Driver DSN
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# Snowflake Driver DSNs
username[:password]@accountname/dbname/schemaname?param1=value1¶mN=valueN
username[:password]@accountname/dbname?param1=value1¶mN=valueN
username[:password]@hostname:port/dbname/schemaname?account=<your_account>¶m1=value1¶mN=valueN
# SQLite Driver DSN
file:/path/to/test.db?cache=shared&mode=ro
# Microsoft SQL Server Driver DSNs
sqlserver://username:password@localhost:1234?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=0123456789
# Google BigQuery DSNs
bigquery://projectid/?param1=value¶m2=value
bigquery://projectid/location?param1=value¶m2=value
# SAP HANA driver DSN
hdb://<user>:<password>@<host>:<port>?<connection-property>=<value>&<connection-property>=<value>&...
hdb://<user>:<password>@<host>:<port>?DATABASENAME=<tenant-db-name>
hdb://?KEY=<keyname>
# Vertica driver DSN
vertica://<user>:<password>@<host>:<port>/<database>?<queryArgs>
AWS Athena 连接字符串
要查询 Amazon Athena 数据库,请在您的 Athena S3 连接字符串 (DNS) 中使用以下查询参数:
- region: (必填) AWS区域。
- accessID: (必填) AWS IAM 访问 ID。
- SecretAccessKey: (必填) AWS IAM 秘钥。
- db: 数据库名称。
- WGRemoteCreation: 控制工作组和标签的创建。
- missingAsDefault: 用默认值替换缺失的数据。
- missingAsEmptyString: 用空字符串替换缺失的数据。
常见的 BigQuery URL 参数
Flux BigQuery 实现使用 Google Cloud Go SDK。通过以下任一方法提供您的认证凭据:
- 标识您的凭据 JSON 文件位置的
GOOGLE_APPLICATION_CREDENTIALS环境变量。 - 通过在您的 BigQuery DSN 中使用
credentialsURL 参数来提供您的 BigQuery 凭据。
BigQuery 凭证 URL 参数
使用凭据 URL 参数在您的 BigQuery DSN 中提供您的 base-64 编码服务帐号、刷新令牌或 JSON 凭据。
BigQuery 证书 URL 参数
bigquery://projectid/?credentials=eyJ0eXBlIjoiYXV0...
SQL Server ADO 认证
使用以下方法之一提供 SQL Server 身份验证凭据作为 ActiveX 数据对象 (ADO) 连接字符串参数:
从环境变量中检索认证凭据
azure auth=ENV
从文件中获取身份验证凭据
azure auth=C:\secure\azure.auth
注意: InfluxDB OSS 和 InfluxDB Cloud 用户界面不提供对底层文件系统的访问,并且不支持从文件中读取凭据。要从文件中检索 SQL Server 凭据,请在本地机器的 Flux REPL 中执行查询。
在连接字符串中指定身份验证凭据
# 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虚拟机中使用托管标识
azure auth=MSI