Cloud Computing

How to Set Up a MySQL Database on AWS: Step-by-Step Guide

If you are building a web application using Node.js, React, Next.js, or any other technology, choosing a reliable database is an important part of your…

D
DevByteTechnical Author
Published
7 min read0 views
How to Set Up a MySQL Database on AWS: Step-by-Step Guide

If you are building a web application using Node.js, React, Next.js, or any other technology, choosing a reliable database is an important part of your development process. Amazon Web Services (AWS) provides a managed database service called Amazon RDS that makes it easy to create, configure, and manage MySQL databases in the cloud.

In this tutorial, you will learn how to set up a MySQL database on AWS using Amazon RDS, configure database access, connect to your database using MySQL Workbench, and prepare it for your application.

Whether you are a beginner or an experienced developer, this step-by-step guide will help you understand the complete AWS MySQL database setup process.

What Is Amazon RDS for MySQL?

Amazon Relational Database Service (Amazon RDS) is a managed database service that allows developers to run relational databases in the AWS cloud without manually managing the underlying database server.

With Amazon RDS for MySQL, AWS handles many administrative tasks, including database backups, software patching, monitoring, and infrastructure maintenance.

Benefits of Using AWS RDS MySQL

  • Managed database service: Reduce the time spent managing database infrastructure.

  • Automated backups: Configure backups to help recover data when necessary.

  • Scalability: Choose suitable compute and storage resources as your application grows.

  • Security: Configure network access, encryption, and database authentication.

  • Monitoring: Track database performance and resource utilization.

  • High availability: Use Multi-AZ deployments for supported high-availability configurations.

Amazon RDS is a useful option for applications such as e-commerce websites, SaaS platforms, admin dashboards, and REST APIs.

Prerequisites

Before creating your AWS MySQL database, make sure you have:

  1. An active AWS account.

  2. Access to the AWS Management Console.

  3. Basic knowledge of MySQL.

  4. MySQL Workbench or another MySQL client.

  5. An application or project that will connect to the database.

Important: AWS resources may incur charges. Check the current pricing and Free Tier eligibility before creating your database.

Step 1: Open the Amazon RDS Console

First, sign in to your AWS account.

  1. Open the AWS Management Console.

  2. Search for Amazon RDS.

  3. Open the RDS dashboard.

  4. Select Databases from the navigation menu.

  5. Click Create database.

You are now ready to configure your MySQL database.

Step 2: Choose MySQL as Your Database Engine

AWS RDS supports multiple database engines, including MySQL, PostgreSQL, MariaDB, and Microsoft SQL Server.

To create a MySQL database:

  1. Select Standard create if you want to configure the database settings manually.

  2. Under Engine options, select MySQL.

  3. Choose a MySQL version supported by Amazon RDS.

For a development project, select a version compatible with your application and database tools.

Choosing the correct database engine and version helps ensure compatibility with your backend application.

Step 3: Configure the Database Instance

Next, configure your database settings.

Database identification

Enter a database identifier, such as:

devbyte-mysql-db

This name identifies your RDS database instance within AWS.

Credentials

Choose a master username, such as:

dbadmin

Create a strong password and store it securely. Avoid using the master account for routine application queries; create a separate database user with only the permissions your application needs.

Instance configuration

Choose a database instance class appropriate for your workload.

For learning and development, consider a small eligible instance if available. For production, select resources based on expected traffic, memory requirements, and query performance.

Also configure storage according to your expected data size and growth.

Tip: Avoid overprovisioning your database during development. You can review and adjust supported instance settings as your project grows.

Step 4: Configure Network and Security Settings

Network configuration is one of the most important steps when setting up an AWS MySQL database.

Your application must be able to reach the database, but unauthorized users must not be able to access it.

Configure the following options:

  • Virtual Private Cloud (VPC): Select the VPC where your application will operate.

  • DB subnet group: Choose an appropriate subnet group for the database.

  • Public access: Select No for most production databases.

  • VPC security group: Choose or create a security group that controls inbound traffic.

MySQL typically uses port 3306.

If you need to connect from MySQL Workbench on your local computer, allow inbound TCP traffic on port 3306 only from your current public IP address. Do not expose the database port to 0.0.0.0/0.

For production environments, prefer private database access through an application server, VPN, bastion host, or another appropriately secured connection method.

Step 5: Create the MySQL Database

After configuring the database instance, credentials, storage, and networking:

  1. Review your configuration.

  2. Check the estimated costs and deployment settings.

  3. Click Create database.

  4. Wait for AWS to provision the instance.

The database status should eventually change to Available.

Provisioning time varies depending on the selected configuration.

Once the instance is available, open its details page to find the database endpoint and port.

The endpoint will look similar to this:

devbyte-mysql-db.abcdefghij.ap-south-1.rds.amazonaws.com

Your actual endpoint will be different. Use the endpoint displayed in your AWS console.

Step 6: Connect to AWS MySQL Using MySQL Workbench

Now you can connect to your database using MySQL Workbench, provided that your network configuration allows the connection.

Open MySQL Workbench and create a new connection.

Enter these details:

  • Connection Name: AWS MySQL Database

  • Hostname: Your RDS endpoint

  • Port: 3306

  • Username: Your configured database username

  • Password: Your database password

Click Test Connection.

If the connection succeeds, save it and open the database connection.

If the connection fails, verify that the RDS instance is available, the endpoint is correct, the security group permits your IP address, and your network routing allows access.

Do not solve connection issues by opening the database to every IP address.

Step 7: Create a Database and Table

After connecting to MySQL, you can create a database and table for your application.

Run the following SQL commands:

CREATE DATABASE devbyte_app;

USE devbyte_app;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(150) UNIQUE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (name, email)
VALUES ('Manjeet', 'manjeet@example.com');

SELECT * FROM users;

These commands create a database called devbyte_app, define a users table, insert a sample record, and retrieve the stored data.

For a real application, replace the sample information with your own data and use appropriate validation.

Step 8: Connect AWS MySQL to a Node.js Application

If you are building a MERN-related backend or another Node.js application, you can connect to MySQL using the mysql2 package.

First, install the dependency:

npm install mysql2 dotenv

Create a .env file:

DB_HOST=your-rds-endpoint
DB_USER=your-app-user
DB_PASSWORD=your-strong-password
DB_NAME=devbyte_app
DB_PORT=3306

Next, create a database connection file:

require("dotenv").config();

const mysql = require("mysql2/promise");

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  port: Number(process.env.DB_PORT) || 3306,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
});

module.exports = pool;

You can import this connection pool into your Express.js routes or services to execute database queries.

Security tip: Never commit your .env file to GitHub. Add it to .gitignore, use a dedicated database user with limited privileges, and consider AWS Secrets Manager for securely managing production credentials. Ensure your application can reach the RDS instance over the configured network.

Step 9: Enable Backups and Monitor Your Database

Before using your database in production, review the following settings:

  • Configure automated backups and an appropriate retention period.

  • Enable encryption at rest and use encrypted connections where appropriate.

  • Monitor CPU utilization, database connections, storage, and query performance.

  • Review database permissions regularly.

  • Configure alerts for important resource thresholds.

  • Test your backup restoration process.

These practices help improve database reliability, security, and maintainability.

Common AWS MySQL Connection Problems

If you cannot connect to your AWS MySQL database, check these common issues:

1. Connection timed out: Verify the security group, routing, network access, and whether the database is publicly or privately accessible.

2. Access denied: Check the username, password, and database permissions.

3. Unknown database: Confirm that the database exists and that the configured database name is correct.

4. Connection refused: Verify the RDS instance status and port configuration.

5. Application connection errors: Check environment variables, DNS resolution, network connectivity, and whether your application server can reach the database.

Avoid making the database publicly accessible simply to troubleshoot a connection issue.

Conclusion

Setting up a MySQL database on AWS using Amazon RDS is a practical way to host a cloud database without managing the database server yourself.

By following this guide, you have learned how to create an AWS RDS MySQL instance, configure network security, connect using MySQL Workbench, create tables, and integrate the database with a Node.js application.

For production applications, prioritize private networking, least-privilege database users, secure credential management, automated backups, encryption, and performance monitoring.

Start with a small development configuration, test your application, and scale your database resources as your requirements increase

D
DevByteAuthor

Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.

Keep Exploring

Related Engineering Dispatches

More guides and architectural patterns you might find valuable.

Browse All Articles↘