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

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

要求Requirements

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

获取连接字符串Get the connection string

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

Get-AzMariaDbConnectionString -Client PHP -Name mydemoserver -ResourceGroupName myresourcegroup
$con=mysqli_init();mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL); mysqli_real_connect($con, "mydemoserver.mariadb.database.chinacloudapi.cn", "myadmin@mydemoserver", {your_password}, {your_database}, 3306);

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

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

后续步骤Next steps