如何使用 PowerShell 生成 Azure Database for PostgreSQL 连接字符串How to generate an Azure Database for PostgreSQL connection string with PowerShell

本文演示如何为 Azure Database for PostgreSQL 服务器生成连接字符串。This article demonstrates how to generate a connection string for an Azure Database for PostgreSQL server. 可以使用连接字符串从许多不同的应用程序连接到 Azure Database for PostgreSQL。You can use a connection string to connect to an Azure Database for PostgreSQL from many different applications.

要求Requirements

本文使用以下指南中创建的资源作为起点:This article uses the resources created in the following guide as a starting point:

获取连接字符串Get the connection string

Get-AzPostgreSqlConnectionString cmdlet 用于生成连接字符串,以便将应用程序连接到 Azure Database for PostgreSQL。The Get-AzPostgreSqlConnectionString cmdlet is used to generate a connection string for connecting applications to Azure Database for PostgreSQL. 下面的示例从 mydemoserver 返回 PHP 客户端的连接字符串。The following example returns the connection string for a PHP client from mydemoserver.

Get-AzPostgreSqlConnectionString -Client PHP -Name mydemoserver -ResourceGroupName myresourcegroup
host=mydemoserver.postgres.database.chinacloudapi.cn port=5432 dbname={your_database} user=myadmin@mydemoserver password={your_password} sslmode=require

Client 参数的有效值包括:Valid values for the Client parameter include:

  • ADO.NETADO.NET
  • JDBCJDBC
  • Node.jsNode.js
  • PHPPHP
  • PythonPython
  • RubyRuby
  • WebAppWebApp

后续步骤Next steps