This folder contains an example Terraform configuration that deploys a MySQL database - using RDS in an Amazon Web Services (AWS) account - that is properly configured for PlanetScale's DB import feature.
It will make sure that the RDS database has the binlog exposed, gtid-mode set to ON and is using ROW-based replication. All these are pre-requisites for imports to work without zero downtime.
If you are going to write a lot of data in your database in a very short amount of time, don't forget the only manual step after the Terraform setup.
- You must have Terraform installed on your computer.
- You must have an Amazon Web Services (AWS) account.
Please note that this example will deploy real resources into your AWS account.
Configure your AWS access keys as environment variables:
export AWS_ACCESS_KEY_ID=(your access key id)
export AWS_SECRET_ACCESS_KEY=(your secret access key)
Optionally, select a password for your database and export it as a Terraform variable:
export TF_VAR_db_password="your_secret_password"
If you do not set this variable, Terraform will query you for the password in the next step
Optionally, edit the variables.tf
to change the name of the database and main.tf
to change the region or add replicas.
Create the RDS database:
terraform init
terraform apply
Now, you can connect with mysql:
mysql -u admin -p$TF_VAR_db_password -h `terraform output -raw address`
(or, if you have not set your password in a variable)
mysql -u admin -pyour_secret_password -h `terraform output -raw address`
Before you import
In order for the replication log not being to small, you would need to type the following in the mysql command prompt:
call mysql.rds_set_configuration('binlog retention hours', 24);
Now, you can follow the steps for PlanetScale import.
Clean up when you're done:
terraform destroy