7 Steps to Connect Magento 2 with Amazon RDS Database

7 Steps to Connect Magento 2 with Amazon RDS Database

[Updated: March 20, 2026] Running your Magento database on the same server as your application creates a single point of failure. One traffic spike and both your web server and database compete for the same CPU and memory.

Amazon RDS separates your database into a managed service with automated backups, patching, and failover. This guide covers the complete setup for Magento 2.4.8 with MySQL 8.4 on RDS, plus production best practices that prevent the most common performance problems.

Key Takeaways

  • Amazon RDS eliminates manual database maintenance for Magento stores with automated backups, patching, and Multi-AZ failover.
  • Magento 2.4.8 requires MySQL 8.4 LTS or MariaDB 11.4 LTS. Amazon RDS supports both.
  • RDS Optimized Writes deliver up to 2x write throughput. Optimized Reads speed up queries by up to 50% using NVMe SSD storage.
  • Aurora offers better performance for large catalogs. Standard RDS MySQL works well for small to mid-size stores.
  • 7-step process from RDS instance creation to verified Magento connection.
  • 10 production best practices covering instance sizing, security, monitoring, and cost optimization.

What Is Amazon RDS for Magento?

Amazon RDS = A managed database service that handles setup, patching, backups, and scaling for your Magento store's MySQL database. You get production-grade reliability without managing the database server yourself.

Perfect for: Magento stores on AWS, teams without dedicated DBAs, businesses that need automated backups and failover.

Not ideal for: Stores with extreme customization needs that require bare-metal database access, or very small projects where a local database is sufficient.

Amazon Relational Database Service runs your Magento database in the cloud as a fully managed service. Instead of provisioning servers, configuring MySQL, scheduling backups, and applying patches, RDS handles all routine database tasks.

Magento 2.4.8 requires MySQL 8.4 LTS or MariaDB 11.4 LTS. Amazon RDS supports both engines, plus Amazon Aurora as a MySQL-compatible alternative with enhanced performance.

RDS integrates with the broader AWS ecosystem. Pair it with ElastiCache for Redis session storage, OpenSearch for catalog search, and CloudFront for static content delivery. This architecture follows the AWS reference design for Magento deployments.

Amazon RDS vs. Amazon Aurora for Magento

Both run MySQL-compatible engines, but they differ in architecture, performance, and cost.

Feature Amazon RDS for MySQL Amazon Aurora
Database Engine Standard MySQL 8.4 LTS MySQL-compatible with custom storage engine
Performance Good for most Magento workloads. Supports Optimized Reads (50% faster queries) and Optimized Writes (2x write throughput) Up to 5x throughput of standard MySQL. Distributed storage architecture for faster reads and writes
Scalability Vertical scaling by changing instance size. Up to 15 read replicas Auto-scaling storage up to 128 TB. Up to 15 read replicas with automatic scaling
High Availability Multi-AZ with standby replica. Manual failover takes 60-120 seconds Multi-AZ by default. Automatic failover completes in under 30 seconds
Backup Automated daily backups. Point-in-time recovery within retention period Continuous incremental backups to S3. Point-in-time recovery to any second
Cost Lower starting cost. db.t4g.medium from ~$50/month Higher base cost. db.r6g.large from ~$165/month. More cost-effective at scale
Best For Small to mid-size Magento stores (under 50K SKUs) Large catalogs (50K+ SKUs), high-traffic stores, mission-critical uptime

Recommendation: Start with RDS MySQL for stores under 50,000 SKUs and moderate traffic. Move to Aurora when you need sub-30-second failover, auto-scaling replicas, or handle catalogs above 100,000 products.

7 Steps to Connect Magento 2 to Amazon RDS

7-step flow diagram showing the process to connect Magento 2 to Amazon RDS

Step 1: Create an RDS Instance

  1. Log in to the AWS Management Console and navigate to the RDS service.
  2. Click "Create database" and select MySQL 8.4 as the engine.
  3. Choose your instance class. For production Magento stores, start with db.r6g.large (2 vCPU, 16 GB RAM) or db.r7g.large for Graviton-based pricing advantages.
  4. Set storage to General Purpose SSD (gp3) with at least 100 GB. Enable storage autoscaling.
  5. Create the database name (e.g., magento2), master username, and a strong password. Record these credentials.
  6. Enable Multi-AZ deployment for production environments.

Instance sizing guidelines:

Store Size Recommended Instance RAM Storage
Development/staging db.t4g.medium 4 GB 20-50 GB
Small store (under 10K SKUs) db.r6g.large 16 GB 100 GB
Mid-size store (10K-100K SKUs) db.r6g.xlarge 32 GB 200-500 GB
Large store (100K+ SKUs) db.r6g.2xlarge+ or Aurora 64 GB+ 500 GB+

Step 2: Configure the Security Group

  1. Open the security group attached to your RDS instance.
  2. Add an inbound rule for MySQL/Aurora (port 3306).
  3. Set the source to your Magento EC2 instance's security group ID, not an IP address. This approach survives instance replacements.

Only your Magento application servers should have access to the database. Never expose RDS to the public internet.

Step 3: Retrieve Connection Details

From the RDS dashboard, select your instance and note:

  • Endpoint (e.g., magento-db.xxxx.us-east-1.rds.amazonaws.com)
  • Port (default: 3306)
  • Database name (from Step 1)
  • Username and password (from Step 1)

Step 4: Update Magento Database Configuration

Open app/etc/env.php on your Magento server. Update the database connection section:

'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => 'magento-db.xxxx.us-east-1.rds.amazonaws.com',
            'dbname' => 'magento2',
            'username' => 'magento_user',
            'password' => 'your_secure_password',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8mb4;',
            'active' => '1',
            'driver_options' => [
                1014 => false
            ]
        ]
    ]
],

Magento 2.4.8 defaults to utf8mb4 collation. Make sure your RDS instance uses utf8mb4_0900_ai_ci as the default character set to match.

Step 5: Run Magento Setup or Test Migration

For new installations: Run the Magento setup command with your RDS connection details:

bin/magento setup:install \
  --db-host="magento-db.xxxx.us-east-1.rds.amazonaws.com" \
  --db-name="magento2" \
  --db-user="magento_user" \
  --db-password="your_secure_password"

For existing stores: Export your current database and import it into RDS:

mysqldump -u root -p magento2 | mysql -h magento-db.xxxx.us-east-1.rds.amazonaws.com -u magento_user -p magento2

Step 6: Test the Connection

  1. Clear the Magento cache: bin/magento cache:clean
  2. Access your store in a browser and verify pages load.
  3. Create a test product, place a test order, and check the admin panel.
  4. Monitor the RDS console for connection metrics and query performance.

If you see "Error establishing a database connection," verify your security group allows traffic from the Magento server and double-check the endpoint and credentials in env.php.

Step 7: Set Up Monitoring

Configure Amazon CloudWatch alarms for your RDS instance:

  • CPU Utilization above 80% for 5 minutes
  • Freeable Memory below 1 GB
  • Database Connections approaching the max for your instance class
  • Read/Write Latency above 20ms

Enable RDS Performance Insights (free for 7-day retention) to identify slow queries and lock contention specific to your Magento workload.

RDS Optimized Reads and Writes for Magento

Amazon RDS offers two performance features that benefit Magento workloads:

Comparison of RDS Optimized Writes (2x throughput) and Optimized Reads (50% faster queries) for Magento

Optimized Writes

Optimized Writes deliver up to 2x write transaction throughput at no extra cost. This feature removes the double-write buffer overhead in MySQL by using AWS-specific storage optimizations.

Impact on Magento: Faster order processing, quicker catalog imports, and improved admin panel responsiveness during bulk operations like price updates or inventory syncs.

Requirements: MySQL 8.0.30 or higher on supported instance types (db.r6g, db.r7g, db.r6gd, db.r7gd, and equivalent).

Optimized Reads

Optimized Reads speed up queries by up to 50% by placing temporary tables on NVMe SSD storage attached to the host server instead of EBS volumes.

Impact on Magento: Faster catalog searches, product filtering, and complex reporting queries. Any Magento operation that generates temporary tables (sorting, aggregations, joins, layered navigation) benefits.

Requirements: Instance types with local NVMe storage: db.r6gd, db.r7gd, db.m6gd, db.m7gd, db.m8gd, db.r8gd.

RDS Proxy for Connection Pooling

RDS Proxy sits between your Magento application and database, pooling and sharing connections. Magento can open hundreds of database connections during traffic spikes. Without connection pooling, you hit the MySQL max_connections limit and requests fail.

RDS Proxy reduces connection overhead by up to 90% and adds automatic failover that's transparent to the application. Add it to your production setup if your store handles more than 100 concurrent users.

10 Best Practices for Magento on Amazon RDS

1. Choose the Right Engine

MySQL 8.4 LTS works well for most Magento stores. Consider Aurora for stores with large catalogs, high write volumes, or strict uptime requirements. Aurora's storage engine handles concurrent reads and writes better than standard MySQL at scale.

2. Size Your Instance for Production

Do not run production Magento on db.t-class instances. These are burstable and lose performance when credits run out. Use db.r6g or db.r7g (memory-optimized) instances for production workloads.

Rule of thumb: Your database should have enough RAM to hold the entire InnoDB buffer pool. For a 10 GB database, provision at least 16 GB RAM.

3. Enable Multi-AZ

Multi-AZ creates a synchronous standby replica in a different Availability Zone. During hardware failure or maintenance, RDS fails over to the standby with minimal downtime. The cost doubles your instance price, but the protection is worth it for any revenue-generating store.

4. Configure Automated Backups

Enable automated backups with a 7-day retention period minimum. Schedule the backup window during your lowest traffic hours. Test point-in-time recovery at least once per quarter to confirm your backups work.

Take manual snapshots before major Magento upgrades or large data imports.

5. Use Read Replicas for Heavy Workloads

Create read replicas to offload reporting queries, catalog browsing, and search indexing from your primary instance. Magento supports split database architecture for Enterprise editions. For Open Source, use application-level routing or a caching layer with Redis to reduce read pressure.

Monitor replica lag. If lag exceeds 1 second, your replica may serve stale data for product prices or inventory.

6. Tune MySQL Parameters

Create a custom RDS parameter group with these Magento-optimized settings:

Parameter Recommended Value Why
innodb_buffer_pool_size 70-80% of instance RAM Keeps hot data in memory
innodb_log_file_size 1-2 GB Reduces checkpoint frequency
max_connections 500-1000 Handles Magento's connection patterns
query_cache_type 0 (disabled) Removed in MySQL 8.0+
innodb_flush_log_at_trx_commit 2 Better write performance (with Multi-AZ for safety)
innodb_io_capacity 3000-10000 Matches gp3/io2 IOPS

7. Secure Your Database

  • Place RDS in a private subnet with no public accessibility.
  • Use security groups to restrict access to Magento application servers only.
  • Enable encryption at rest (AES-256) and encryption in transit (SSL/TLS).
  • Use IAM database authentication instead of password-based auth for additional security.
  • Rotate credentials every 90 days using AWS Secrets Manager.

8. Monitor and Optimize Performance

Use CloudWatch and Performance Insights together for complete visibility into your Magento database performance:

  • CloudWatch: CPU, memory, connections, IOPS, network throughput
  • Performance Insights: Top SQL queries, wait events, lock contention
  • Slow query log: Enable and review weekly. Queries over 2 seconds need index optimization.

Set up CloudWatch alarms for CPU above 80%, freeable memory below 1 GB, and disk queue depth above 10.

9. Plan for Scaling

Start with vertical scaling (larger instance type) for quick relief. When vertical scaling hits limits, add read replicas for read-heavy workloads.

Combine RDS with ElastiCache for session and page caching, OpenSearch for catalog search, and CloudFront as a CDN. This distributes load across purpose-built services instead of overloading a single database.

10. Optimize Costs with Graviton and Reserved Instances

AWS Graviton-based instances (db.r7g, db.r6g) deliver up to 20% better price-performance compared to x86 equivalents. MySQL 8.4 runs without modification on Graviton processors.

For predictable workloads, Reserved Instances save 30-60% compared to On-Demand pricing. A 1-year All Upfront reservation on db.r6g.large drops the effective cost from ~$165/month to ~$95/month.

Troubleshooting Common Magento RDS Issues

Issue Cause Fix
Slow page loads Undersized instance or missing indexes Check RDS CPU/memory in CloudWatch. Run EXPLAIN on slow queries. Add indexes for frequent WHERE clauses.
Connection refused Security group misconfigured Verify inbound rule allows port 3306 from your Magento security group. Check RDS instance is in "Available" state.
"Too many connections" Magento opens connections faster than MySQL closes them Increase max_connections parameter. Add RDS Proxy for connection pooling. Check for connection leaks in custom extensions.
High CPU during reindex Full catalog reindex hammers the database Schedule reindex during off-peak hours. Use "Update on Schedule" mode instead of "Update on Save" for large catalogs.
Replication lag on read replicas Long-running queries on primary or undersized replica Match replica instance class to primary. Kill long queries over 60 seconds. Check for table-level locks.
Storage full Binary logs, slow query logs, or temp tables filling storage Enable storage autoscaling. Purge old binary logs. Review tmp_table_size and max_heap_table_size settings.
Failover takes too long DNS caching on Magento server Set MySQL connect timeout to 5 seconds. Use the RDS endpoint hostname (not IP). Clear PHP DNS cache after failover.
Extension compatibility Third-party extensions use deprecated MySQL features Test extensions in staging first. Check for GROUP BY issues with MySQL 8.4 strict mode. Contact extension vendor for updates.

Pros and Cons of Amazon RDS for Magento

Pros Cons
Automated backups, patching, and failover Higher monthly cost than self-managed MySQL
Multi-AZ deployment for production reliability No root OS access to the database server
Scales from small stores to enterprise workloads Aurora costs 2-3x more than standard RDS MySQL
Integrates with CloudWatch, IAM, and Secrets Manager Network latency between EC2 and RDS adds 1-3ms per query
Optimized Reads/Writes boost Magento performance Requires AWS knowledge for proper configuration

FAQ

1. What MySQL version does Magento 2.4.8 need on Amazon RDS?

Magento 2.4.8 requires MySQL 8.4 LTS. Amazon RDS supports this version with the latest minor release being MySQL 8.4.8 (February 2026). MariaDB 11.4 LTS is an alternative supported by both Magento and RDS.

2. Should I use RDS MySQL or Aurora for my Magento store?

Use RDS MySQL for stores with fewer than 50,000 SKUs and moderate traffic. Choose Aurora for large catalogs, high-traffic stores, or when you need sub-30-second automatic failover. Aurora costs more but delivers up to 5x the throughput of standard MySQL.

3. How much does Amazon RDS cost for a Magento store?

A production-ready db.r6g.large instance costs about $165/month On-Demand. With a 1-year Reserved Instance, this drops to about $95/month. Add storage ($0.115/GB-month for gp3), backup storage, and data transfer. Total database cost for a mid-size store ranges from $120 to $350/month.

4. What is the difference between RDS Optimized Reads and Optimized Writes?

Optimized Writes increase write transaction throughput by up to 2x by eliminating the MySQL double-write buffer. Optimized Reads speed up queries by up to 50% by placing temporary tables on local NVMe SSD storage. Both features are available at no extra charge on supported instance types.

5. Can I use RDS Proxy with Magento?

Yes. RDS Proxy pools database connections between Magento and MySQL, reducing connection overhead by up to 90%. This prevents "too many connections" errors during traffic spikes. RDS Proxy costs about $0.015 per vCPU per hour on top of your RDS instance cost.

6. How do I migrate an existing Magento database to Amazon RDS?

Export your database with mysqldump, create an RDS instance with matching MySQL version (8.4), import the dump file, update app/etc/env.php with the new RDS endpoint, and clear the Magento cache. For large databases (over 10 GB), use AWS Database Migration Service for minimal downtime migration.

7. Does Multi-AZ deployment double my RDS cost?

Yes, Multi-AZ creates a synchronous standby replica that doubles compute and storage costs. For a db.r6g.large instance, this means about $330/month instead of $165. The investment prevents revenue loss from database outages.

8. What monitoring should I set up for Magento on RDS?

Enable CloudWatch alarms for CPU (above 80%), memory (below 1 GB free), connections (above 80% of max), and latency (above 20ms). Activate Performance Insights for query-level analysis. Review the slow query log weekly and optimize any query taking more than 2 seconds.

Summary

Amazon RDS gives your Magento store a production-grade database without the operational burden of managing MySQL yourself. Combined with Multi-AZ failover, automated backups, and features like Optimized Reads and Writes, RDS handles the database layer so you can focus on your store.

For stores running on AWS, the combination of RDS (or Aurora for large catalogs), ElastiCache for Redis, and OpenSearch creates a resilient, scalable architecture. Start with RDS MySQL 8.4, right-size your instance, and enable Multi-AZ for any store generating revenue.

Consider managed Magento hosting on AWS where the complete infrastructure, including RDS configuration, monitoring, and optimization, is handled for you.

CEO & Co-Founder

Raphael Thiel co-founded MGT-Commerce in 2011 together with Stefan Wieczorek and has built it into a leading Magento hosting provider serving 5,000+ customers on AWS. With 25+ years in e-commerce and cloud infrastructure, he oversees hosting architecture for enterprise clients. He also co-founded CloudPanel, an open-source server management platform.


Get the fastest Magento Hosting! Get Started