Skip to content

Latest commit

 

History

History
225 lines (161 loc) · 6.48 KB

azure-mysql-db.md

File metadata and controls

225 lines (161 loc) · 6.48 KB

Azure Database for MySQL Service

Azure Database for MySQL is a relational database service in the Microsoft cloud based on MySQL Community Edition database engine. Azure Database for MySQL delivers:

  • Predictable performance at multiple service levels

  • Dynamic scalability with no application downtime

  • Built-in high availability

  • Data protection

Behaviors

Provision

  1. Create a server.

Provision-Poll

  1. Check whether creating server succeeds or not.

  2. Configure firewall rules

Bind

 1. Collect credentials.

Unbind

Do nothing

Deprovision

  1. Delete the server.

Deprovision-Poll

  1. Check whether deleting server succeeds or not.

Create an Azure Database for MySQL service

  1. Get the service name and plans
cf marketplace

Sample output:

service              plans                                                                         description
azure-mysqldb        basic50*, basic100*, standard100*, standard200*, standard400*, standard800*   Azure MySQL Database Service

If you can not find the service name, please use the following command to make the plans public.

cf enable-service-access azure-mysqldb
  1. Create a service instance

Configuration parameters are supported with the provision request. These parameters are passed in a valid JSON object containing configuration parameters, provided either in-line or in a file.

cf create-service azure-mysqldb $service_plan $service_instance_name -c $path_to_parameters

Supported configuration parameters:

{
    "resourceGroup": "<resource-group>",        // [Required] Unique. Only allow up to 90 characters
    "location": "<azure-region-name>",          // [Required] support westus and northeurope only
    "mysqlServerName": "<server-name>",         // [Required] Unique. Server name cannot be empty or null. It can contain only lowercase letters, numbers and '-', but can't start or end with '-' or have more than 63 characters. 
    "mysqlServerParameters": {
        "allowMysqlServerFirewallRules": [      // [Optional] If present, ruleName, startIpAddress and endIpAddress are mandatory in every rule.
            {
                "ruleName": "<rule-name-0>",    // The rule name can only contain 0-9, a-z, A-Z, -, _, and cannot exceed 128 characters
                "startIpAddress": "xx.xx.xx.xx",
                "endIpAddress": "xx.xx.xx.xx"
            },
            {
                "ruleName": "<rule-name-1>",
                "startIpAddress": "xx.xx.xx.xx",
                "endIpAddress": "xx.xx.xx.xx"
            }
        ],
        "properties": {
            "version": "5.6" | "5.7",
            "sslEnforcement": "Enabled" | "Disabled",
            "storageMB": 51200 | 179200 | 307200 | ... | 1075200, // 51200, 51200+128000*1, 51200+128000*2 ... 51200+128000*8
            "administratorLogin": "<server-admin-name>",
            "administratorLoginPassword": "<server-admin-password>"
        }
    },
    "mysqlDatabaseName": "<database-name>"      // [Required] Unique. Database name cannot be empty or null. It can contain only lowercase letters, numbers and '-', but can't start or end with '-' or have more than 63 characters. 
}

For example:

cf create-service azure-mysqldb basic100 mysqldb -c examples/mysqldb-example-config.json

The contents of examples/mysqldb-example-config.json:

{
    "resourceGroup": "azure-service-broker",
    "location": "eastus",
    "mysqlServerName": "generated-string",
    "mysqlServerParameters": {
        "allowMysqlServerFirewallRules": [
            {
              "ruleName": "all",
              "startIpAddress": "0.0.0.0",
              "endIpAddress": "255.255.255.255"
            }
        ],
        "properties": {
            "version": "5.6",
            "sslEnforcement": "Disabled",
            "storageMB": 51200,
            "administratorLogin": "generated-string",
            "administratorLoginPassword": "generated-string"
        }
    },
    "mysqlDatabaseName": "generated-string"
}

NOTE: Please remove the comments in the JSON file before you use it.

Above parameters are also the defaults if the broker operator doesn't change broker default settings. You can just run the following command to create a service instance without the json file:

cf create-service azure-mysqldb basic100 mysqldb
  1. Check the operation status of creating the service instance

The creating operation is asynchronous. You can get the operation status after the creating operation.

cf service $service_instance_name

For example:

cf service mysqldb

More information.

Using the services in your application

Binding

cf bind-service $app_name $service_instance_name

For example:

cf bind-service demoapp mysqldb

Format of Credentials

Verify that the credentials are set as environment variables

cf env $app_name

The credentials have the following format:

"credentials": {
  "mysqlServerName": "mysqlservera",
  "mysqlDatabaseName": "mysqldba",
  "mysqlServerFullyQualifiedDomainName": "mysqlservera.mysql.database.azure.com",
  "administratorLogin": "ulrich",
  "administratorLoginPassword": "u1r8chP@ss",
  "jdbcUrl": "jdbc:mysql://mysqlservera.mysql.database.azure.com:3306/mysqldba?user=<administratorLogin>&password=<administratorLoginPassword>&verifyServerCertificate=true&useSSL=true&requireSSL=false",
  "hostname": "mysqlservera.mysql.database.azure.com",
  "port": 3306,
  "name": "mysqldba",
  "username": "ulrich@mysqlservera", 
  "password": "u1r8chP@ss",
  "uri": "mysql://ulrich%40mysqlservera:u1r8chP@ss@mysqlservera.mysql.database.azure.com:3306/mysqldba?ssl=true"
}

NOTE: The part hostname - uri is compatible with Cloud Foundry MySQL Release.

Unbinding

cf unbind-service $app_name $service_instance_name

For example:

cf unbind-service demoapp mysqldb

Delete the service instance

cf delete-service $service_instance_name -f

For example:

cf delete-service mysqldb -f