Step 1 - Configuring the database 

Create a read-only login which LogStash will use.
Additionally, make sure the database server accepts TCP connections from remote machines. 

Step 2 - Obtaining the JDBC driver

To read from the database, LogStash needs a Type 4 JDBC driver. Here's our favorite list of popular database engines and their corresponding driver download links.

Step 3 - Obtaining LogStash 

Follow this article to get and make LogStash ready.

Step 4 - Configuring LogStash

Open the  config/logstash.conf file, and add the following within the input  clause:

jdbc {
    tracking_column => {{tracking_col_name}}
    use_column_value => {{use_column_value}}
    statement => "SELECT {{fields or *}} FROM {{table}} WHERE {{tracking_col_name}} > :sql_last_value"
    jdbc_connection_string => "jdbc:{{database_type}}://{{hostname}};databaseName={{dbname}}"
    jdbc_driver_class => "{{database_class}}"
    jdbc_driver_library => "{{path-to-jar}}"
    jdbc_user => "{{username}}"
    jdbc_password => "{{password}}"
    jdbc_page_size => 10
    add_field => { "table" => "{{table}}" }
}

Replace all the placeholders (values in {{ }} ) as necessary, and adjust the statement to only retrieve what wish to send.
If you would like to stream more than one table, add additional jdbc  caluses. 

Step 5 - running / restarting LogStash

Continue from step 5 in the LogStash installation guide.

That's it! Please let us know if you felt anything is missing in this guide. We'd love to hear your ideas for improvement!

Did this answer your question?