Creating a MySQL Database instance in RDS and connecting to it with MySQL Workbench
In this lab I will create a encrypted RDS database. Then I will connect to it using a MySQL Workbench and create database, table and insert some data. Then I will take a snapshot of the database and export it to S3.
- Create a RDS database
- Connect to database using MySQL Workbench
- Take snapshot and export it to S3
- AWS account
- MySQL Workbench
- Create a S3 bucket.
- Create an symmetric KMS Key. No need to change permissions. Copy the key’s ARN.
- Create a Security group for RDS DB Instance. Allow inbound traffic for MySQL/Aurora from anywhere.
- Create an Amazon RDS DB Instance with MySQL engine, with t2.micro instance and as publicly accessible.
- Connect to RDS Database using the MySQL Workbench. To connect to a database on a DB instance using MySQL Workbench, find the endpoint (DNS name) and port number for your DB Instance. Under Connectivity & security section, copy and note the endpoint and port.
Click on the plus icon. And provide connection endpoint and credentials.
After successfully connecting and opening the database, you can create tables and perform various queries over the connected database.
- Create a sample database and a table. Create a database by running:
CREATE DATABASE SchoolDB;
Then switch to the database
Create a table
CREATE TABLE IF NOT EXISTS subjects ( subject_id INT AUTO_INCREMENT, subject_name VARCHAR(255) NOT NULL, teacher VARCHAR(255), lesson TEXT, PRIMARY KEY (subject_id) ) ENGINE=INNODB;
Insert some data into table
INSERT INTO subjects(subject_name, teacher, lesson) VALUES ('English', 'John Taylor', 'Chapter one'); INSERT INTO subjects(subject_name, teacher, lesson) VALUES ('Science', 'Mary Smith', 'Chapter four'); INSERT INTO subjects(subject_name, teacher, lesson) VALUES ('Maths', 'Ted Miller', 'Chapter ten'); INSERT INTO subjects(subject_name, teacher, lesson) VALUES ('Arts', 'Suzan Carpenter', 'Chapter seven');
- Take a Snapshot from the existing DB Instance in the RDS Dashboard. Select the created DB Instance and click on Actions. Click Take snapshot from the options.
- Export the DB snapshot to S3. Select the created snapshot and click on the Actions. Click on Export to Amazon S3 from the options. Under the S3 destination, select the created S3 from the drop-down. Select the created KMS key from the drop-down or enter the ARN that we noted while creating the key.
This may take up to 20-25 minutes as it is exporting the whole database
- Check the exported data in Amazon S3. Once the export is completed, navigate to the created S3 Bucket.