fbpx

How to Execute SQL File on MySQL RDS using awscli

To execute a SQL script on an Amazon RDS for MySQL instance using the AWS CLI, you can use the aws rds-data execute-statement command. This command allows you to execute a SQL statement or script on a DB instance.

Here is an example of how you might use the execute-statement command to execute a SQL script on a DB instance named mydbinstance:

				
					aws rds-data execute-statement \
    --resource-arn arn:aws:rds:us-east-1:123456789012:cluster:mydbinstance \
    --database mydatabase \
    --secret-arn arn:aws:secretsmanager:us-east-1:123456789012:secret:mysecret \
    --sql "source /path/to/myscript.sql"

				
			

This command executes the SQL script at /path/to/myscript.sql on the mydatabase database of the mydbinstance DB instance. It uses the secret identified by mysecret to authenticate to the database.

Note that executing a SQL script on a DB instance can cause changes to the data in the database. You should be careful and make sure that the script will not cause any unintended changes or disruptions.

For more information about the execute-statement command and the other available RDS Data API commands, see the https://docs.aws.amazon.com/cli/latest/reference/rds-data/index.html

Share:

Facebook
Twitter
Pinterest
LinkedIn

Social Media

Most Popular

Get The Latest Updates

Subscribe To Our Weekly Newsletter

No spam, notifications only about new products, updates.

Categories