Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am wondering if there is such a way to automatically run SQL queries and export to file (example: csv file) and then FTP to desired location? It seems simple and would need something like this as it would be very time consuming doing this manually.

Any info is greatly appreciated!

share|improve this question
add comment

2 Answers

You can do that with CRON jobs (or schedule windows task).

Query to export to csv looks like:

SELECT id, name INTO OUTFILE '/tmp/report.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'

You can schedule the query to run with CRON and the ftp commands too.

share|improve this answer
add comment

cron jobs (man cron for usage) are how you would schedule the process.

Off the top of my head, your actual script (run by the cron job) would do the following:

  • use mysqldump to export the database
  • call FTP with a list of commands to run (ftp server < commands.txt)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.