How to generate an Azure Database for MySQL connection string with PowerShell

APPLIES TO: Azure Database for MySQL - Single Server

Important

Azure Database for MySQL - Single Server is on the retirement path. We strongly recommend for you to upgrade to Azure Database for MySQL - Flexible Server. For more information about migrating to Azure Database for MySQL - Flexible Server, see What's happening to Azure Database for MySQL Single Server?

This article demonstrates how to generate a connection string for an Azure Database for MySQL server. 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

The Get-AzMySqlConnectionString cmdlet is used to generate a connection string for connecting applications to Azure Database for MySQL. 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.azure.com", "myadmin@mydemoserver", {your_password}, {your_database}, 3306);

Valid values for the Client parameter include:

  • ADO.NET
  • JDBC
  • Node.js
  • PHP
  • Python
  • Ruby
  • WebApp

Next steps