Migration DB on EC2 to RDS
AWS RDS Masterclass Commands
Databases on EC2 Instance - Demo:
Begin Configuration:
$ sudo su -
$ yum -y install mariadb-server wget
$ systemctl enable mariadb
$ systemctl start mariadb
$ yum update -y
Set Environmental Variables:
DBName=rds=prod
DBPassword=admin@12345
DBRootPassword=admin@54321
DBUser=rdsuser
Database Setup on EC2 Instance:
echo "CREATE DATABASE ${DBName};" >> /tmp/db.setup
echo "CREATE USER '${DBUser}' IDENTIFIED BY '${DBPassword}';" >> /tmp/db.setup
echo "GRANT ALL PRIVILEGES ON *.* TO '${DBUser}'@'%';" >> /tmp/db.setup
echo "FLUSH PRIVILEGES;" >> /tmp/db.setup
mysqladmin -u root password "${DBRootPassword}"
mysql -u root --password="${DBRootPassword}" < /tmp/db.setup
rm /tmp/db.setup
Adding some dummy data to the Database inside EC2 Instance:
mysql -u root --password="$DBRootPassword}"
USE rds-prod;
CREATE TABLE table (id INT, name VARCHAR(45));
INSERT INTO table VALUES(1, 'Raghunath'), (2, 'IT-Infosoft'), (3, 'Raghu-Infosoft'), (4, 'Zoom-Technology');
SELECT * FROM table;
Real-time-Used:
Migration of Database in EC2 Instance to RDS Database:
$ mysqldump -u root -p rds-prod > rds-prod_dump.sql
Enter password:
$ ls -lrt
$ mysql -h rds-prod-database.aws2023vtc25.us-east-1.rds.amazon.com -P 3306 -u rdsuser -p rds-prod < rds-proddump.sql
Enter password:
$ mysql -h rds-prod-database.aws2023vtc25.us-east-1.rds.amazon.com -P 3306 -u rdsuser -p
Enter password:
$ SHOW databases;
$ USE rds-prod;
$ SELECT * FROM tables;
ConversionConversion EmoticonEmoticon