هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Terraform/ User Guide/ Relational Database Service (RDS)/ Creating an RDS MySQL DB Instance

Creating an RDS MySQL DB Instance

Updated on 2022-02-10 GMT+08:00

Application Scenario

MySQL is an open-source relational database management system. The LAMP solution (Linux + Apache + MySQL + Perl/PHP/Python) makes it much efficient to develop web applications. This section describes how to create an RDS MySQL DB instance by using Terraform scripts.

Related Resources

huaweicloud_rds_instance

Procedure

  1. Plan and create a VPC, subnet, and security group.

    1. For details about how to create a network resource, see Configuring the Network.
    2. If you want to use a created network resource, use data source to obtain the corresponding resource ID. The following is an example:
      data "huaweicloud_vpc" "myvpc" {
        name = var.vpc_name
      }
      data "huaweicloud_vpc_subnet" "mysubnet" {
        vpc_id = data.huaweicloud_vpc.myvpc.id
        name   = var.subnet_name
      }
      data "huaweicloud_networking_secgroup" "mysecgroup" {
        name = var.secgroup_name
      }

  2. Create an RDS MySQL DB instance.

    Example 1: Using new network resources and a random password
    data "huaweicloud_availability_zones" "myaz" {}
    
    resource "random_password" "mypassword" {
      length           = 12
      special          = true
      override_special = "!@#%^*-_=+"
    }
    resource "huaweicloud_rds_instance" "myinstance" {
      name                = "mysql_instance"
      flavor              = "rds.mysql.c2.large.ha"
      ha_replication_mode = "async"
      vpc_id              = huaweicloud_vpc.myvpc.id
      subnet_id           = huaweicloud_vpc_subnet.mysubnet.id
      security_group_id   = huaweicloud_networking_secgroup.mysecgroup.id
      availability_zone   = [
        data.huaweicloud_availability_zones.myaz.names[0],
        data.huaweicloud_availability_zones.myaz.names[1]
      ]
      db {
        type     = "MySQL"
        version  = "8.0"
        password = random_password.mypassword.result
      }
      volume {
        type = "ULTRAHIGH"
        size = 40
      }
    }

    Example 2: Using existing network resources
    data "huaweicloud_availability_zones" "myaz" {}
    
    resource "huaweicloud_rds_instance" "myinstance" {
      name                = "mysql_instance"
      flavor              = "rds.mysql.c2.large.ha"
      ha_replication_mode = "async"
      vpc_id              = data.huaweicloud_vpc.myvpc.id
      subnet_id           = data.huaweicloud_vpc_subnet.mysubnet.id
      security_group_id   = data.huaweicloud_networking_secgroup.mysecgroup.id
      availability_zone   = [
        data.huaweicloud_availability_zones.myaz.names[0],
        data.huaweicloud_availability_zones.myaz.names[1]
      ]
      db {
        type     = "MySQL"
        version  = "8.0"
        password = var.rds_password
      }
      volume {
        type = "ULTRAHIGH"
        size = 40
      }
    }

  3. Configure variables.

    Create the variables.tf file, enter the following information, and save the file. You can change the variable values based on your needs.

    variable "vpc_name" {
      default = "vpc-basic"
    }
    variable "vpc_cidr" {
      default = "172.16.0.0/16"
    }
    variable "subnet_name" {
      default = "subent-basic"
    }
    variable "subnet_cidr" {
      default = "172.16.10.0/24"
    }
    variable "subnet_gateway" {
      default = "172.16.10.1"
    }
    variable "primary_dns" {
      default = "100.125.1.250"
    }

  4. Create resources.

    1. Run terraform init to initialize the environment.
    2. Run terraform plan to view resources.
    3. After you confirm that the resource information is correct, run terraform apply to start resource creation.
    4. Run terraform show to view information about the created RDS instance.

Table 1 Parameter description

Resource Name

Parameter

Description

huaweicloud_rds_instance

name

(Mandatory) Database instance name. Under the same tenant, database instances of the same type can have the same name.

  • The value must be 4 to 64 characters in length and start with a letter. It is case-sensitive and can contain only letters, digits, hyphens (-), and underscores (_).

flavor

(Mandatory) DB instance flavor. In this example, rds.mysql.c2.large.ha is used. You can query the instance flavor via huaweicloud_rds_flavors.

ha_replication_mode

(Optional) Replication mode for the standby DB instance. For MySQL, the value can be async or semisync.

availability_zone

(Mandatory) AZ where the instance is located. Multiple AZs are supported for master/standby instances. For details, see Regions and Endpoints.

vpc_id

(Mandatory) ID of the VPC to which the instance belongs.

subnet_id

(Mandatory) ID of the subnet to which the instance belongs.

security_group_id

(Mandatory) ID of the security group to which the instance belongs.

db

type

(Mandatory) Database engine type.

  • Value options: MySQL, PostgreSQL, and SQLServer

version

(Mandatory) Database engine version. For MySQL, versions 5.6, 5.7, and 8.0 are supported.

password

(Mandatory) Database password.

The value contains 8 to 32 characters. Only letters, digits, and the following special characters are supported: ~!@#%^*-_=+?

Enter a strong password to prevent security risks such as brute force cracking.

port

(Optional) Database port.

  • The MySQL database port ranges from 1024 to 65535 (excluding 12017 and 33071, which are occupied by the RDS system). The default value is 3306.

volume

type

(Mandatory) Disk type of the database instance.

  • Options:

    ULTRAHIGH: SSD type

    ULTRAHIGHPRO: ultra-high I/O (advanced), which supports ultra-high performance (advanced) DB instances.

size

(Mandatory) Disk space of the database instance.

  • The value must be a multiple of 10 and range from 40 GB to 4,000 GB.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback