Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

556
Views
How to run SQL query inside docker container and export results outside the container (.CSV)

In SQL server I tried to export a CSV file using below command

mysql> mysql -u username -p --host=rdshostname --port=rdsport --batch -e "select * from yourtable" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//' > export.csv

But no luck, So How I can export the above query result to CSV file?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The easiest approach is to run the query inside the container and then export the result to file on the host.

docker exec -it some-mysql bash -c 'mysql -h myhost -u root -pPassword --database sample --batch -e "select * from company"' 

This will print the query result, now redirect the resulting output to file on the host.

docker exec -it some-mysql bash -c 'mysql -h myhost -u root -pPassword --database sample --batch -e "select * from company"'  > sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//' > company.csv

then upload the file to s3 from the host

aws s3 cp company.csv s3://mybucket/rds/mydb/table.csv

company sample databse

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!