search
HomeDatabaseMysql TutorialMigrating to Amazon RDS
Migrating to Amazon RDSSep 18, 2024 pm 08:06 PM

Migrating to Amazon RDS

A lab on migrating to Amazon RDS typically involves transferring an existing on-premises or cloud-hosted database to Amazon's Relational Database Service (RDS). The goal is to reduce the operational burden of managing databases by leveraging AWS's managed service for automated backups, patching, monitoring, and scaling.

Objective:

  • Create an Amazon RDS MariaDB instance by using the AWS CLI.
  • Migrate data from a MariaDB database on an EC2 instance to an Amazon RDS MariaDB instance.
  • Monitor the Amazon RDS instance by using Amazon CloudWatch metrics.

Summary:

  • Creating an Amazon RDS instance by using the AWS CLI
  • Migrating application data to the Amazon RDS instance
  • Configuring the website to use the Amazon RDS instance
  • Monitoring the Amazon RDS database

The application database runs in an Amazon Elastic Compute Cloud (Amazon EC2) Linux, Apache, MySQL, and PHP (LAMP) instance along with the application code. The instance has a T3 small instance type and runs in a public subnet so that internet clients can access the website. A CLI Host instance resides in the same subnet to facilitate the instance's administration by using the AWS Command Line Interface (AWS CLI).

Creating an Amazon RDS instance by using the AWS CLI:

  • Configure the AWS CLI.
  • Create the following prerequisite components required to build the Amazon RDS instance:
  • A security group firewall for the Amazon RDS instance
  • Two private subnets and a database subnet group
  • Create the Amazon RDS MariaDB instance.
  • On the AWS Management Console, in the Search bar, enter and choose EC2 to open the EC2 Management Console.
  • In the navigation pane, choose Instances.
  • From the list of instances, select the CLI Host instance.
  • Choose Connect.
  • On the EC2 Instance Connect tab, choose Connect.
  • To set up the AWS CLI profile with credentials, in the EC2 Instance Connect terminal, run the following command: ‘aws configure’
  • Enter the user's access key and secret access key.
  • Create Security Group: Set up CafeDatabaseSG to protect the RDS instance.
  • Add Inbound Rule: Allow only MySQL requests (TCP protocol, port 3306) from instances in CafeSecurityGroup.
  • Create Private Subnets: Establish two private subnets (CafeDB Private Subnet 1 and CafeDB Private Subnet 2).
  • Create Database Subnet Group: Define a CafeDB Subnet Group for RDS, associating it with the private subnets.
  • Create CafeDatabaseSG Security Group: Run command: aws ec2 create-security-group --group-name CafeDatabaseSG --description "Security group for Cafe database" --vpc-id

Output: Note the GroupId for future use.

  • Create Inbound Rule for CafeDatabaseSG:
    Run command:
    aws ec2 authorize-security-group-ingress
    --group-id
    --protocol tcp --port 3306
    --source-group

  • Verify Inbound Rule:
    Run command:
    aws ec2 describe-security-groups
    --query "SecurityGroups[*].[GroupName,GroupId,IpPermissions]"
    --filters "Name=group-name,Values='CafeDatabaseSG'"

  • Create CafeDB Private Subnet 1
    Run command:
    aws ec2 create-subnet
    --vpc-id
    --cidr-block 10.200.2.0/23
    --availability-zone

Output: Note the SubnetId for future use.

  • Create CafeDB Private Subnet 2
    Run command:
    aws ec2 create-subnet
    --vpc-id
    --cidr-block 10.200.10.0/23
    --availability-zone
    Output: Note the SubnetId for future use.

  • Create DB Subnet Group
    Run command:
    aws rds create-db-subnet-group
    --db-subnet-group-name "CafeDB Subnet Group"
    --db-subnet-group-description "DB subnet group for Cafe"
    --subnet-ids
    --tags "Key=Name,Value= CafeDatabaseSubnetGroup"

  • Create the CafeDBInstance

Run the following command to create the MariaDB instance with the specified configuration:
Run command:
aws rds create-db-instance
--db-instance-identifier CafeDBInstance
--engine mariadb
--engine-version 10.5.13
--db-instance-class db.t3.micro
--allocated-storage 20
--availability-zone
--db-subnet-group-name "CafeDB Subnet Group"
--vpc-security-group-ids
--no-publicly-accessible
--master-username root --master-user-password 'Re:Start!9'

Key settings:

  • DB instance identifier: CafeDBInstance
  • Engine: MariaDB (version 10.5.13)
  • Instance class: db.t3.micro
  • Allocated storage: 20 GB
  • Security group: CafeDatabaseSG
  • Username: root
  • Password: Re:Start!9
    The creation of the database instance may take up to 10 minutes.

  • Monitor the Status of the DB Instance

After running the creation command, monitor the status of the database by running the following command:
Run command:

aws rds describe-db-instances
--db-instance-identifier CafeDBInstance
--query "DBInstances[*].[Endpoint.Address,AvailabilityZone,PreferredBackupWindow,BackupRetentionPeriod,DBInstanceStatus]"

What to watch: The command will return information such as the endpoint address, availability zone, backup window, retention period, and the status of the instance.
Initially, the status will show as creating and then progress through modifying, backing-up, and finally to available.

  • Continue running the status command every few minutes until the status of the database shows available. Run command: aws rds describe-db-instances --db-instance-identifier CafeDBInstance --query "DBInstances[*].[DBInstanceStatus]"

Migrating application data to the Amazon RDS instance:

  • Connect to the EC2 Instance (CafeInstance)
  • In the terminal, run the following command to create a backup of the local cafe_db database:
    Run Command:
    mysqldump --user=root --password='Re:Start!9'
    --databases cafe_db --add-drop-database > cafedb-backup.sql

  • Review the Backup File
    You can review the contents of the backup using the less command:
    Run Command:
    less cafedb-backup.sql

Use arrow keys or Page Up/Down to navigate and q to quit.

  • Restore the Backup to the Amazon RDS Database
    Run the following command to restore the backup to the RDS instance. Replace with your actual RDS instance endpoint:
    Run Command
    mysql --user=root --password='Re:Start!9'
    --host=

  • Verify the Data Migration
    Open an interactive MySQL session to the RDS instance:
    Run Command:
    mysql --user=root --password='Re:Start!9'
    --host=
    cafe_db

Once inside the MySQL session, verify the data in the product table by running the following SQL query:
sql
Run Command:
select * from product;

Ensure that the returned data matches the original database.

  • Exit the MySQL Session After verifying the data, exit the MySQL session by entering: Run Command exit

Note: Keep the SSH window open for future tasks.

Configuring the website to use the Amazon RDS instance

  • Open AWS Systems Manager
    In the AWS Management Console, search for Systems Manager in the search bar.
    Navigate to Systems Manager.

  • Access Parameter Store
    In the left navigation pane, choose Parameter Store.

  • Edit the /cafe/dbUrl Parameter
    From the My parameters list, select /cafe/dbUrl.
    Choose Edit to modify the parameter value.

  • Update the Database URL
    In the Parameter details page, replace the existing value with the RDS Instance Database Endpoint Address.
    The format should be like:
    Run Command:

cafedbinstance.xxxxxxx.us-west-2.rds.amazonaws.com

Click Save changes to update the parameter.

  • Test the Website

Open a new browser window and paste the CafeInstanceURL that you saved earlier (e.g., http://ec2-xx-xx-xx-xx.compute-1.amazonaws.com).
The café website’s homepage should load.

  • Verify the Database Connection Go to the Order History tab on the website. Check the number of orders displayed. It should match the number from the local database before the migration.

Monitoring the Amazon RDS database

  • Open the Amazon RDS Console
    In the AWS Management Console, search for RDS.
    Go to the RDS Management Console.

  • Select the Database
    In the left navigation pane, choose Databases.
    From the list, select cafedbinstance.
    You will now see detailed information about the database.

  • View Monitoring Metrics
    Click on the Monitoring tab.
    This tab displays key metrics, including:

  1. CPUUtilization
  2. DatabaseConnections
  3. FreeStorageSpace
  4. FreeableMemory
  5. WriteIOPS
  6. ReadIOPS
  • Monitor DatabaseConnections Metric
    Look for the DatabaseConnections graph. If needed, go to page 2 or 3 of the metrics charts.
    This graph tracks the number of active database connections.

  • Connect to the RDS Database
    In the CafeInstance terminal window, run the following command to open a MySQL session:
    Run Command
    mysql --user=root --password='Re:Start!9'
    --host=
    cafe_db

Replace with your RDS instance endpoint.

  • Run an SQL Query Inside the MySQL session, run the following SQL query to retrieve data from the product table: sql Run Command: select * from product;

The query should return the data from the product table.

  • Check the DatabaseConnections Graph
    In the RDS console, click the DatabaseConnections graph.
    You should now see 1 active connection from the interactive SQL session.
    If the graph does not update, wait 1 minute and click Refresh.

  • Close the MySQL Session
    In the CafeInstance terminal window, exit the MySQL session:

Run Command
exit

  • Monitor the Connections After Disconnecting
    Wait for 1 minute, then refresh the DatabaseConnections graph in the RDS console.
    The number of connections should now show as 0.

  • Explore Other Metrics
    You can explore additional metrics such as CPUUtilization, FreeStorageSpace, WriteIOPS, and ReadIOPS by reviewing their graphs on the Monitoring tab.

The above is the detailed content of Migrating to Amazon RDS. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Reduce the use of MySQL memory in DockerReduce the use of MySQL memory in DockerMar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared libraryHow to solve the problem of mysql cannot open shared libraryMar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin)Run MySQl in Linux (with/without podman container with phpmyadmin)Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overviewWhat is SQLite? Comprehensive overviewMar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guideRunning multiple MySQL versions on MacOS: A step-by-step guideMar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software