简体   繁体   中英

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

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 } 
}

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.

Logstash 无法加载驱动程序,因为它在错误的位置寻找驱动程序,您应该始终指定驱动程序的完整路径,例如:

jdbc_driver_library => "/opt/drivers/mysql-connector-java-8.0.15.jar"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM