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

备注

将要查看的是 Azure Database for MySQL 的新服务。You are viewing the new service of Azure Database for MySQL. 若要查看经典 MySQL Database for Azure 的文档,请访问此页To view the documentation for classic MySQL Database for Azure, please visit this page.

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

要求Requirements

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

获取连接字符串Get the connection string

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

Get-AzMySqlConnectionString -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.mysql.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