Logstash output jdbc Error: java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl

Use logstash to synchronize one database to another

Use cmd to execute logstash synchronization processing data under windows successfully but publish to linux and execute java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl

I read many articles and found that there is no such kind of solution

input {
  jdbc {
    # Database drive path
    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 "
    # Drive name
    jdbc_driver_class => " com.mysql.jdbc.Driver "
    # Database connection string
    jdbc_connection_string => " jdbc:mysql://****?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true "
    # database username
    jdbc_user => ""
    # Database password
    jdbc_password => "" 
    # The time interval for repeating the import task: minute -hour-day-month- week
     schedule => " */1 * * * * * "
    # Imported table (query SQL, can filter data)
    statement => " SELECT * from hot_data limit 1000 "
    # Default time zone
    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 " ]
  }
}

There is no problem with the execution of the above in windows cmd, and the data will be written, but there will be problems under linux. Many methods have been tried and finally solved.

input {
  jdbc {
    # Database drive path
    jdbc_driver_library => " /home/fanxu/logstash/logstash-7.0.0/vendor/jar/jdbc/mysql-connector-java-8.0.26.jar "
    # Drive name
    jdbc_driver_class => " com.mysql.jdbc.Driver "
    # Database connection string
    jdbc_connection_string => " jdbc:mysql://****?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true "
    # database username
    jdbc_user => " "
    # Database password
    jdbc_password => " " 
    # The time interval for repeating the import task: minute -hour-day-month- week
     schedule => " */1 * * * * * "
    # Imported table (query SQL, can filter data)
    statement => " SELECT * from hot_data limit 1000 "
    # Default time zone
    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 " ]
  }
}

Add two jars under the /vendor/jar/jdbc/ path, and use them separately to write data normally

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *