7

I am getting java version and mysql-connect-java.jar compatibility issue with logstash.

can any one tell me which version of mysql-connect-java.jar is compatible with which version of java?

Error:

com.mysql.cj.jdbc.Driver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?

my current java version is

openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.16.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

I have tried with below mysql connector jar files but every one fails.

mysql-connector-java-8.0.16.jar
mysql-connector-java-8.0.15.jar
mysql-connector-java-6.0.5.jar
mysql-connector-java-5.1.46.jar
mysql-connector-java-5.1.4.jar

Logstash config file is mysql.conf

input {
    jdbc {
        jdbc_connection_string => "jdbc:mysql://localhost:3306/prbi"
        jdbc_user => "root"
        jdbc_password => ""
        jdbc_driver_library => "mysql-connector-java-8.0.15.jar" #tried above every jar
        jdbc_driver_class => "com.mysql.cj.jdbc.Driver" #tried com.mysql.jdbc.Driver too
        schedule => "* * * * *"
        use_column_value => true
        tracking_column => "%{id}"
        clean_run => true
        statement => "SELECT * from tmp_j_summaryrepor"
    }
}
output {
    elasticsearch {
    hosts => ['http://localhost:9200']
    index => "prsummaryreport"
    document_type => "prsummaryreport"
    document_id => "%{id}" # It is a Primary Key of table
    }
    stdout { codec => json_lines } 
}
Juned Ansari
  • 5,035
  • 7
  • 56
  • 89

3 Answers3

15

for logstash 6.2.x and above, prefer adding the drivers under:

/usr/share/logstash/logstash-core/lib/jars/

and rather keep the jdbc_driver_library empty. this has been quoted in many of the elastic.co forums too.

khanna
  • 718
  • 10
  • 24
2

Logstash can't load the driver because it's looking for the driver in the wrong place, you should always specify the full path to a driver e.g.:

jdbc_driver_library => "/opt/drivers/mysql-connector-java-8.0.15.jar"
Michael Dz
  • 3,655
  • 8
  • 40
  • 74
0

In my case, I specified the full path of jdbc_driver_library to: "/opt/drivers/mysql-connector-java-8.0.15.jar"

It was working prior to a restart and then suddenly started throwing the error.

I found out that for some reason the jdbc.jar file was corrupted, the size had changed to 0KB. I redownloaded the Jar, dropped it in the full path and restarted.

So you might just want to check that your jdbc file is fine. It should not be 0KB.

Lae
  • 832
  • 1
  • 13
  • 34