logstash output jdbc 报错 java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl

使用 logstash 一个数据库同步到另外一个数据库

在windows 下使用cmd 执行 logstash同步处理数据成功但是发布到 linux 下去执行报  java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl

看了很多文章发现没有这一类的解决办法

input {
  jdbc {
    # 数据库驱动路径
    jdbc_driver_library => "D:\logstash-7.14.0-windows-x86_64\logstash-7.14.0\vendor\jar\jdbc\mysql-connector-java-5.1.46-bin.jar"
    # 驱动名称
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    # 数据库的连接字符串
    jdbc_connection_string => "jdbc:mysql://****?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true"
    # 数据库用户名
    jdbc_user => ""
    # 数据库密码
    jdbc_password => ""
    # 重复执行导入任务的时间间隔  分-时-日-月-星期
     schedule => "*/1 * * * * *"
    # 导入的表(查询SQL,可以过滤数据)
    statement => "SELECT * from hot_data limit 1000"
    #  默认时区
    jdbc_default_timezone => "Asia/Shanghai"
    }
}

filter{
    json{
        source => "message"
    }
}

output {
  stdout{
        codec=>rubydebug{}
  }
  jdbc {
    driver_jar_path => "D:\logstash-7.14.0-windows-x86_64\logstash-7.14.0\vendor\jar\jdbc\mysql-connector-java-5.1.46-bin.jar"
    driver_class => "com.mysql.jdbc.Driver"
    connection_string => "jdbc:mysql://***?user=&password="
    statement => [ "INSERT INTO hot_data (title, url, content, cnt, site_name, hot_tag) VALUES(?, ?, ?, ?, ?, ?)", "title", "url" , "content", "cnt", "site_name", "hot_tag"]
  }
}

以上在windows cmd执行是没有问题的,数据也会写入,但是在linux下就会出现问题尝试了很多种办法终于解决

input {
  jdbc {
    # 数据库驱动路径
    jdbc_driver_library => "/home/fanxu/logstash/logstash-7.0.0/vendor/jar/jdbc/mysql-connector-java-8.0.26.jar"
    # 驱动名称
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    # 数据库的连接字符串
    jdbc_connection_string => "jdbc:mysql://****?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true"
    # 数据库用户名
    jdbc_user => ""
    # 数据库密码
    jdbc_password => ""
    # 重复执行导入任务的时间间隔  分-时-日-月-星期
     schedule => "*/1 * * * * *"
    # 导入的表(查询SQL,可以过滤数据)
    statement => "SELECT * from hot_data limit 1000"
    #  默认时区
    jdbc_default_timezone => "Asia/Shanghai"
    }
}
 
filter{
    json{
        source => "message"
    }
}
 
output {
  stdout{
        codec=>rubydebug{}
  }
  jdbc {
    driver_jar_path => "/home/fanxu/logstash/logstash-7.0.0/vendor/jar/jdbc/mysql-connector-java-5.1.46-bin.jar"
    driver_class => "com.mysql.jdbc.Driver"
    connection_string => "jdbc:mysql://****?user=&password="
    statement => [ "INSERT INTO hot_data (title, url, content, cnt, site_name, hot_tag) VALUES(?, ?, ?, ?, ?, ?)", "title", "url" , "content", "cnt", "site_name", "hot_tag"]
  }
}

在/vendor/jar/jdbc/ 路径下新增两个jar,分开使用就会正常写入数据

logstash output jdbc 报错 java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl

上一篇:Linux Centos7安装mongodb并设置开机启动


下一篇:sql常见优化