Error logstash.inputs.jdbc Unable to connect to database


(Medaly Ahmed) #1

I am a beginner in logstash.
I want to load my database "mydb" in the inddex "test". but I find an error with logstash:
"error logstash.inputs.jdbc Unable to connect to database"
this is my config file:

    `input {
 jdbc {
    jdbc_driver_library => "C:\logstash-6.7.1\bin\mysql-connector-java-5.1.15-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://localhost:3306/mydb"
    jdbc_user => "medaly"
	jdbc_password => "123456"
	statement => "SELECT * from contacts"
  }
}



output {
  elasticsearch { hosts => ["localhost:9200"] index => "test" }
  stdout { codec => rubydebug }
}

if I execute the command, it displays:

C:\logstash-6.7.1\bin>logstash -f logstash-factures.conf
Sending Logstash logs to C:/logstash-6.7.1/logs which is now configured via log4j2.properties
[2019-04-16T12:03:48,623][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2019-04-16T12:03:48,654][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.7.1"}
[2019-04-16T12:04:02,577][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2019-04-16T12:04:03,436][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
[2019-04-16T12:04:03,780][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2019-04-16T12:04:03,858][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2019-04-16T12:04:03,858][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
[2019-04-16T12:04:03,905][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
[2019-04-16T12:04:03,920][INFO ][logstash.outputs.elasticsearch] Using default mapping template
[2019-04-16T12:04:03,998][INFO ][logstash.outputs.elasticsearch] Index Lifecycle Management is set to 'auto', but will be disabled - Your Elasticsearch cluster is before 7.0.0, which is the minimum version required to automatically run Index Lifecycle Management
[2019-04-16T12:04:03,998][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2019-04-16T12:04:04,717][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x409742fb run>"}
[2019-04-16T12:04:04,780][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2019-04-16T12:04:05,436][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
[2019-04-16T12:04:07,155][ERROR][logstash.inputs.jdbc     ] Unable to connect to database. Tried 1 times {:error_message=>"Java::JavaSql::SQLException: The server time zone value 'Temps universel coordonn├®' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support."}
[2019-04-16T12:04:07,202][ERROR][logstash.pipeline        ] A plugin had an unrecoverable error. Will restart this plugin.
  Pipeline_id:main
  Plugin: <LogStash::Inputs::Jdbc jdbc_user=>"medaly", jdbc_password=><password>, statement=>"SELECT * from contacts", jdbc_driver_library=>"C:\\logstash-6.7.1\\bin\\mysql-connector-java-5.1.15-bin.jar", jdbc_connection_string=>"jdbc:mysql://localhost:3306/mydb", id=>"16c5b88811c5bf3585ffe06fd0b66bf9d8247979d1cf1e74ff374b93c2dff4e7", jdbc_driver_class=>"com.mysql.jdbc.Driver", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_63cae9c8-53d2-41ca-a80f-2d2c386a04dc", enable_metric=>true, charset=>"UTF-8">, jdbc_paging_enabled=>false, jdbc_page_size=>100000, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdbc_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connection_retry_attempts_wait_time=>0.5, parameters=>{"sql_last_value"=>1970-01-01 00:00:00 UTC}, last_run_metadata_path=>"C:\\Users\\medaly/.logstash_jdbc_last_run", use_column_value=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>true, lowercase_column_names=>true>
  Error: Java::JavaSql::SQLException: The server time zone value 'Temps universel coordonn├®' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
  Exception: Sequel::DatabaseConnectionError
  Stack: com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(com/mysql/cj/jdbc/exceptions/SQLError.java:129)
.......

(Guy Boertje) #2

Google search for serverTimezone + jdbc


(Medaly Ahmed) #3

Thanks sir @guyboertje
how can i resolve this error of the server time zone ?


(Guy Boertje) #4

What timezone are your timestamps recorded in in the MySQL DB?

If UTC then you can add some parameters to the jdbc connection string.

jdbc:mysql://localhost/mydb?useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=UTC

Double convert timezone when parse datetime from sql
(Medaly Ahmed) #5

thank you sir, it works