Use this skill whenever the user needs to set up self-hosted MySQL with replication on EC2 instances. Triggers on mentions of MySQL master-slave, MySQL replication setup, self-hosted MySQL on EC2, Terraform MySQL, or MySQL 8.4 installation. Also applies when the user wants to create a MySQL environment for Datadog DBM testing.
Provision two EC2 instances and set up MySQL 8.4 LTS master-slave replication using Terraform and shell scripts.
The complete setup is documented in README.md. Two phases:
The Terraform scripts in scripts/ create 2 EC2 instances (master and slave) with public IPs:
cd scripts/
terraform init
terraform plan
terraform apply
Use the bundled shell scripts:
# Install MySQL 8.4 on both instances
bash scripts/install-mysql.sh
# Configure the master
bash scripts/setup-master.sh
# Configure the slave
bash scripts/setup-slave.sh
# Test replication
bash scripts/test-replication.sh
# On the master: verify replication is active
mysql -u root -p -e "SHOW MASTER STATUS\G"
# On the slave: verify replication is running
mysql -u root -p -e "SHOW REPLICA STATUS\G"
# Check: Replica_IO_Running = Yes, Replica_SQL_Running = Yes
# Test: create a table on master, verify it appears on slave
Cause: Incorrect master host, port, or credentials in replication config.
Fix: Run SHOW REPLICA STATUS\G on the slave and check Last_Error. Reconfigure with correct master details.
Cause: apt repository not configured for MySQL 8.4.
Fix: Run scripts/install-mysql.sh which adds the MySQL APT repository automatically.