How to create MySQL user and grant permissions in AWS RDS

AWS RDS (Relational Database Service) is a fully-managed service that makes it easy to set up, operate, and scale a relational database in the cloud. Here’s how you can create a new MySQL user and grant permissions in AWS RDS:

  1. First, connect to the RDS instance using the MySQL command-line client. You can do this by running the command “mysql -h <hostname> -u <username> -p” and enter the password when prompted.
  2. Next, create a new MySQL user by running the following command:
CREATE USER '<username>'@'<hostname>' IDENTIFIED BY '<password>';
  1. Once the user is created, you can grant the user permission to access the database by running the following command:
GRANT <permission> ON <database>.* TO '<username>'@'<hostname>';
  1. To grant all permissions, use the command “GRANT ALL PRIVILEGES”, instead of <permission>
  2. You can also grant specific permissions such as SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER and etc.
  3. After granting the permissions, you need to flush the privileges by running the command “FLUSH PRIVILEGES”
  4. To revoke permissions, use the command “REVOKE <permission> ON <database>.* FROM ‘<username>’@'<hostname>’;”

It’s important to note that, you will need to replace the placeholders with the appropriate values for your RDS instance, such as the hostname, username, password, database, and permission.

Additionally, you can use the AWS RDS web interface to create and manage users and permissions.

It’s recommended to use the least privilege principle, which means that you should grant the minimum permissions required for the user to perform its intended tasks.

Leave a Comment