Migrating a MariaDB Database to Amazon RDS
By Bishal Dhimal | Dec 2025
📌 Table of Contents
Objectives
Step 1: Create an RDS Database Instance
Step 2: Export Data Using mysqldump
Step 3: Connect a SQL Client to RDS
Step 4: Migrate Data to RDS
Step 5: Configure Web Application
Optional: MySQL Setup on EC2
References
Objectives
- Create an RDS database instance.
- Export data from a MariaDB database using
mysqldump. - Connect a SQL client to an RDS database.
- Migrate data from a MariaDB database on EC2 to RDS.
- Update a web application to use the new RDS database.
1️⃣ Step 1: Create an RDS Database Instance
In the AWS Management Console:
- Go to RDS → Databases → Create database.
- Select Engine: MariaDB/MySQL.
- Choose Template: Free-tier (for testing) or Production (for prod workloads).
- Set DB instance identifier (e.g.,
prod-rds-db). - Configure VPC, Subnet Group, and Security Groups for network access.
- Enable Public Access if required and configure backup, encryption, and monitoring as per production best practices.
2️⃣ Step 2: Export Data from MariaDB Using mysqldump
On the EC2 instance hosting MariaDB:
mysqldump --databases -u -p > /path/to/db_backup.sql
Tips: Use the --single-transaction flag for InnoDB tables to avoid locking.
3️⃣ Step 3: Connect a SQL Client to RDS
# Connect using hostname
mysql -h -u -p
# Or
mysql --hostname -u -p
Ensure your RDS security group allows inbound traffic from your client IP.
4️⃣ Step 4: Migrate Data to RDS
Restore the database backup to RDS:
# Option 1: From within mysql client
mysql -u -p -h
CREATE DATABASE ;
USE ;
SOURCE /path/to/db_backup.sql;
# Option 2: Direct import from shell
mysql -u -p -h <
Production tips:
- Use parameterized transactions for large datasets.
- Consider
aws s3 cpto upload the dump to S3 and then import using EC2 with higher network throughput. - Verify row counts and indexes after import.
5️⃣ Step 5: Configure Web Application
- Update your web application's configuration to point to the new RDS endpoint.
- Use AWS Secrets Manager to securely store database credentials.
- Stop the old MariaDB service on EC2 to prevent accidental writes:
sudo systemctl stop mariadb - Test application functionality and connection.
Optional: Install & Configure MySQL on EC2
Useful if you need a local test environment before migrating:
# Install MySQL
sudo apt update
sudo apt install mysql-server -y
# Secure installation
sudo mysql_secure_installation
# Create a new MySQL user
sudo mysql -u root -p
CREATE USER ''@'%' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO ''@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
# Configure MySQL to allow remote access
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# Change: bind-address = 127.0.0.1 → bind-address = 0.0.0.0
# Restart MySQL service
sudo systemctl restart mysql
# Test connection locally
mysql -u -p
# Test connection remotely (if remote access enabled)
mysql -u -h -p