Aws how to create a second database in the same rds instance on aws rds

July 13, 2021 . 2 MIN READ

https://medium.com/@hbayraktar/how-to-create-a-second-database-in-the-same-rds-instance-on-aws-rds-984666b228af

 

https://aws.amazon.com/premiumsupport/knowledge-center/duplicate-master-user-mysql/

Amazon RDS DB instance that is running MySQL?

Last updated: 2020-08-20

I want to have another user with the same permissions as the master user for my Amazon Relational Database Service (Amazon RDS) or Amazon Aurora MySQL DB instance. How do I duplicate or clone the master user?

Resolution

An RDS DB instance that runs MySQL can have only one master user, but it’s possible to create a new user that has all the same permissions as the master user. To create a new user that has master permissions, follow these steps:

  1. Run the SHOW GRANTS command to get a list of the permissions currently available to the master user, and copy that list of permissions to use later:

mysql> SHOW GRANTS for master_username;

The command provides output similar to the following:

+——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————–+| Grants for master_user@% |+——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————–+| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, LOAD FROM S3, SELECT INTO S3, INVOKE LAMBDA, INVOKE SAGEMAKER, INVOKE COMPREHEND ON *.* TO ‘master_user’@’%’ WITH GRANT OPTION |+——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————–+

Note: In the command above, the master user has the user name master_user.

  1. Create a new user by running the CREATE USER command:

mysql> CREATE USER ‘new_master_user’@’%’ IDENTIFIED BY ‘password’;

Note: Replace new_master_user and password with your user name and password.

  1. Grant the list of permissions you got in step 1 to the new user by running the GRANT command:

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO ‘new_master_user’@’%’ WITH GRANT OPTION;

The new user now has the same permissions as the master user.

 

 

 

 

 

How to create a second database in the same RDS instance on AWS RDS

If you want to create a second database schema in running RDS instance. So you may follow the below steps.

1-Connect your RDS instance through master password.

# mysql -uusername -ppassword -h rds-hostname

2-Now in RDS instance (MySQL) shell prompt. You can create a new database and a new user

mysql> CREATE USER ‘newusername’@’%’ IDENTIFIED BY ‘password’;
mysql> CREATE DATABASE newdatabase;
mysql> GRANT ALL PRIVILEGES on newdatabase.* To newusername@’%’;
mysql> FLUSH PRIVILEGES;
mysql> SHOW databases;

3- Now you be able to login with the new_user with new_database

# mysql -unewusername -ppassword -h rds-hostname

4- You be able to restore the dump (from bash shell) in your new database.

# mysql -unewusername -ppassword -h rds-hostname –database < dump.sql

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *