Template: MySQL SELECT to CSV file with SFTP Upload
Summary
This template generates CSV data from MySQL database Server. Using this template, you can fetch data from MySQL database Server, transform it into CSV file which will be saved on SFTP server.
Prerequisites
This template assumes that the following prerequisites are in place:
- The MySQL database user has permissions to read data from the tables specified in the query.
- The SFTP server user should have the permissions to connect and write the files that Frends needs to upload.
Implementation and Usage Notes
This template creates a new CSV file based on the data from the SQL query.
The variable SelectionCriteria provides the possibility to add conditions to the SELECT statement. This variable can be left empty.
If the file already exists on the SFTP server, it will be overwritten.
Example CSV data
email;firstname;lastname;title
john@example.org;John;Smith;Mr
jane@example.org;Jane;Doe;Ms
john@example.org;John;Smith;Mr
jane@example.org;Jane;Doe;Ms
john@example.org;John;Smith;Mr
jane@example.org;Jane;Doe;Ms
Error Handling
This template does not handle transient errors separately, however the connection to the SFTP server and MySQL database are retried three time before failing.
The template does not handle any SQL errors that may occur - the errors will be thrown as exceptions.
Template Process Variables
| Name | Description |
|---|---|
| Directory | File directory for the CSV file on the SFTP server. |
| FileName | File name for the file on the SFTP server. |
| ServerAddress | SFTP server address. |
| ServerUser | SFTP server user. |
| ServerPasswordSecret | SFTP server user's password. |
| TableName | Name of the database table. |
| ColumnNames | A comma separated list of the columns that are to be selected. |
| SelectionCriteria | The WHERE criteria for selecting the correct data from the database. |
| ConnectionStringSecret | Connection string to access the database. |