2

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!

Jarred
  • 41
  • 1
  • 4

2 Answers2

2

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.

laurent
  • 2,035
  • 16
  • 13
1

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)
Hyppy
  • 15,458
  • 1
  • 37
  • 59