全部产品
Search
文档中心

资源编排:ALIYUN::PolarDBX::Database

更新时间:May 04, 2023

ALIYUN::PolarDBX::Database类型用于创建数据库。

语法

{
  "Type": "ALIYUN::PolarDBX::Database",
  "Properties": {
    "CharacterSetName": String,
    "DBInstanceId": String,
    "Mode": String,
    "DatabaseName": String,
    "DatabaseDescription": String,
    "Accounts": List
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

CharacterSetName

String

字符集。

取值:

  • utf8

  • gbk

  • latin1

  • utf8mb4

DBInstanceId

String

PolarDB-X实例的ID。

Mode

String

创建数据库时选择的模式。

取值:

  • auto:该模式的数据库支持自动分区,即创建表时无需指定分区键。

  • drds:该模式的数据库不支持自动分区,创建表时需使用专用的分库分表语法指定分库分表键。

DatabaseName

String

数据库的名称。

DatabaseDescription

String

数据库描述信息。

Accounts

List

账户列表。

更多信息,请参见Accounts属性

Accounts语法

"Accounts": [
  {
    "AccountPrivilege": String,
    "AccountName": String
  }
]

Accounts属性

属性名称

类型

必须

允许更新

描述

约束

AccountPrivilege

String

给新创建的账号授权某数据库的权限。

取值:

  • ReadWrite

  • ReadOnly

  • DMLOnly

  • DDLOnly

AccountName

String

创建的数据库授权的指定账号名称。

返回值

Fn::GetAtt

  • CharacterSetName:字符集

  • DBInstanceId:PolarDB-X实例的ID。

  • DatabaseName:创建的数据库名称。

  • DatabaseDescription:数据库描述信息。

  • Accounts:账户列表。

示例

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  CharacterSetName:
    Type: String
    Description: |-
      Character set, which supports the following character sets:
      - **utf8 * *
      - **gbk**
      - **latin1 * *
      - **utf8mb4 * *.
    AllowedValues:
      - utf8
      - gbk
      - latin1
      - utf8mb4
    Default: utf8
  DBInstanceId:
    Type: String
    Description: The ID of the instance.
    Default: drdshh****
  DatabaseName:
    Type: String
    Description: The name of the database.
    Default: test1
  Accounts:
    Type: Json
    Description: List of accounts.
    Default:
      - AccountPrivilege: ReadWrite
        AccountName: test1
Resources:
  ExtensionResource:
    Type: ALIYUN::PolarDBX::Database
    Properties:
      CharacterSetName:
        Ref: CharacterSetName
      DBInstanceId:
        Ref: DBInstanceId
      DatabaseName:
        Ref: DatabaseName
      Accounts:
        Ref: Accounts
Outputs:
  CharacterSetName:
    Description: Character set, which supports the following character sets:.
    Value:
      Fn::GetAtt:
        - ExtensionResource
        - CharacterSetName
  DBInstanceId:
    Description: The ID of the instance.
    Value:
      Fn::GetAtt:
        - ExtensionResource
        - DBInstanceId
  DatabaseName:
    Description: The name of the database.
    Value:
      Fn::GetAtt:
        - ExtensionResource
        - DatabaseName
  DatabaseDescription:
    Description: Database description information.
    Value:
      Fn::GetAtt:
        - ExtensionResource
        - DatabaseDescription
  Accounts:
    Description: List of accounts.
    Value:
      Fn::GetAtt:
        - ExtensionResource
        - Accounts

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "CharacterSetName": {
      "Type": "String",
      "Description": "Character set, which supports the following character sets:\n- **utf8 * *\n- **gbk**\n- **latin1 * *\n- **utf8mb4 * *.",
      "AllowedValues": [
        "utf8",
        "gbk",
        "latin1",
        "utf8mb4"
      ],
      "Default": "utf8"
    },
    "DBInstanceId": {
      "Type": "String",
      "Description": "The ID of the instance.",
      "Default": "drdshh****"
    },
    "DatabaseName": {
      "Type": "String",
      "Description": "The name of the database.",
      "Default": "test1"
    },
    "Accounts": {
      "Type": "Json",
      "Description": "List of accounts.",
      "Default": [
        {
          "AccountPrivilege": "ReadWrite",
          "AccountName": "test1"
        }]
    }
  },
  "Resources": {
    "ExtensionResource": {
      "Type": "ALIYUN::PolarDBX::Database",
      "Properties": {
        "CharacterSetName": {
          "Ref": "CharacterSetName"
        },
        "DBInstanceId": {
          "Ref": "DBInstanceId"
        },
        "DatabaseName": {
          "Ref": "DatabaseName"
        },
        "Accounts": {
          "Ref": "Accounts"
        }
      }
    }
  },
  "Outputs": {
    "CharacterSetName": {
      "Description": "Character set, which supports the following character sets:.",
      "Value": {
        "Fn::GetAtt": [
          "ExtensionResource",
          "CharacterSetName"
        ]
      }
    },
    "DBInstanceId": {
      "Description": "The ID of the instance.",
      "Value": {
        "Fn::GetAtt": [
          "ExtensionResource",
          "DBInstanceId"
        ]
      }
    },
    "DatabaseName": {
      "Description": "The name of the database.",
      "Value": {
        "Fn::GetAtt": [
          "ExtensionResource",
          "DatabaseName"
        ]
      }
    },
    "DatabaseDescription": {
      "Description": "Database description information.",
      "Value": {
        "Fn::GetAtt": [
          "ExtensionResource",
          "DatabaseDescription"
        ]
      }
    },
    "Accounts": {
      "Description": "List of accounts.",
      "Value": {
        "Fn::GetAtt": [
          "ExtensionResource",
          "Accounts"
        ]
      }
    }
  }
}