com.mysql.jdbc.Driver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library
Asked Answered
B

3

8

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 } 
}
Breeches answered 20/6, 2019 at 9:22 Comment(10)
on my maven project with java 8, i have mysql-connector-java-5.1.36.jar. try it to see if it works.Rippy
@Sahzeb, do you know where is it documented? which version is compatible with which jar?Breeches
@Shahzeb, same error, with mysql-connector-java-5.1.36.jar version, can you tell me your exact version of java?Breeches
if you don't specify version in pom.xml file (maven project). it is resolved by maven in spring boot.Rippy
#43006656Rippy
Where is your driver located? Have you tried the full path for jdbc_driver_library?Heidy
yes path is correct and it is located in same directoryBreeches
@Michael Dz, you were right, it is a path problem, when i shift file to other directory it is working fineBreeches
I resolved problem by shifting jar file from /etc/logstash/conf.d/ folder to Home directory in ubuntu. finally worked with java version 8 with mysql-connector-java-5.1.36.jarBreeches
@JunedAnsari feel free to post your comment as an answer and accept it if it worked for you.Naomanaomi
H
17

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.

Harriettharrietta answered 25/9, 2019 at 11:27 Comment(1)
Thanks! This fix works for Logstash 7.1 on Mac MojaveScandal
H
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"
Heidy answered 20/6, 2019 at 11:3 Comment(0)
L
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.

Launcher answered 7/12, 2020 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.