SQL query to Automatically Export to file and FTP?

5,027

Solution 1

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.

Solution 2

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:
5,027

Related videos on Youtube

Jarred
Author by

Jarred

Updated on September 18, 2022

Comments

  • Jarred
    Jarred almost 2 years

    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!