# How to connect mysql database by logstash?

**URL:** <https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004>\
**Category:** Logstash\
**Created:** [September 20, 2016, 10:58am UTC](https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004 "2016-09-20T10:58:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajay\_shanker](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@ajay\_shanker](https://discuss.elastic.co/u/ajay_shanker)\
**Post date:** [September 20, 2016, 10:58am UTC](https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004/1 "2016-09-20T10:58:42Z")

</div>

step 1.I installed logstash in c drive and create a  
simple-out.conf file with this code  
# file: simple-out.conf  
input {  
jdbc {  
# Postgres jdbc connection string to our database, mydb  
jdbc\_connection\_string =\> "jdbc:postgresql://127.0.0.1:5432/sortable"  
# The user we wish to execute our statement as  
jdbc\_user =\> "root"  
jdbc\_password =\> ""  
# The path to our downloaded jdbc driver  
jdbc\_driver\_library =\> "../lib/postgresql-9.4.1211.jre6.jar"  
# The name of the driver class for Postgresql  
jdbc\_driver\_class =\> "org.postgresql.Driver"  
# our query  
statement =\> "SELECT \* from bookmarks"  
}  
}  
output {  
stdout { codec =\> json\_lines }  
}

step 2: Placed postgresql-9.4.1211.jre6.jar file in to lib directory.  
step 3: Open cmd window and run this command  
C:\logstash\bin\>logstash -f c:\logstash\bin\simple-out.conf

Then we get command prompt return following error::  
C:\logstash\bin\>logstash -f simple-out.conf  
io/console not supported; tty will not be manipulated  
Settings: Default pipeline workers: 4  
?[31mUnable to connect to database. Tried 1 times {:error\_message=\>"org.postgres  
ql.Driver not loaded, try installing jdbc-postgres gem", :level=\>:error}?[0m  
?[31mPipeline aborted due to error {:exception=\>#\<Sequel::AdapterNotFound: org.p  
ostgresql.Driver not loaded, try installing jdbc-postgres gem\>, :backtrace=\>["C:  
/logstash/vendor/bundle/jruby/1.9/gems/sequel-4.33.0/lib/sequel/adapters/jdbc.rb  
:59:in `load_driver'", "C:/logstash/vendor/bundle/jruby/1.9/gems/sequel-4.33.0/l ib/sequel/adapters/jdbc/postgresql.rb:3:in`(root)'", "org/jruby/RubyKernel.java  
:1040:in `require'", "C:/logstash/vendor/bundle/jruby/1.9/gems/polyglot-0.3.5/li b/polyglot.rb:65:in`require'", "C:/logstash/vendor/bundle/jruby/1.9/gems/sequel  
-4.33.0/lib/sequel/database/connecting.rb:1:in `(root)'", "C:/logstash/vendor/bu ndle/jruby/1.9/gems/sequel-4.33.0/lib/sequel/database/connecting.rb:98:in`load\_  
adapter'", "C:/logstash/vendor/bundle/jruby/1.9/gems/sequel-4.33.0/lib/sequel/ad  
apters/jdbc.rb:361:in `adapter_initialize'", "C:/logstash/vendor/bundle/jruby/1. 9/gems/sequel-4.33.0/lib/sequel/database/misc.rb:146:in`initialize'", "C:/logst  
ash/vendor/bundle/jruby/1.9/gems/sequel-4.33.0/lib/sequel/database/connecting.rb  
:67:in `connect'", "C:/logstash/vendor/bundle/jruby/1.9/gems/sequel-4.33.0/lib/s equel/core.rb:108:in`connect'", "org/jruby/RubyKernel.java:1479:in `loop'", "C: /logstash/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/lib/logstash/pl ugin_mixins/jdbc.rb:109:in`jdbc\_connect'", "C:/logstash/vendor/bundle/jruby/1.9  
/gems/logstash-input-jdbc-3.0.2/lib/logstash/plugin\_mixins/jdbc.rb:106:in `jdbc_ connect'", "C:/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/l ib/logstash/plugin_mixins/jdbc.rb:158:in`prepare\_jdbc\_connection'", "C:/logstas  
h/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/lib/logstash/inputs/jdb  
c.rb:167:in `register'", "org/jruby/RubyArray.java:1613:in`each'", "C:/logstash  
/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:  
330:in `start_inputs'", "C:/logstash/vendor/bundle/jruby/1.9/gems/logstash-core- 2.3.1-java/lib/logstash/pipeline.rb:329:in`start\_inputs'", "C:/logstash/vendor/  
bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:180:in `start_workers'", "C:/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-j ava/lib/logstash/pipeline.rb:136:in`run'"], :level=\>:error}?[0m  
stopping pipeline {:id=\>"main"}  
The signal HUP is in use by the JVM and will not work correctly on this platform  
How to fixed this error?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 20, 2016, 8:04pm UTC](https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004/2 "2016-09-20T20:04:41Z")

</div>

What if you try using an absolute path to the jar file in your `jdbc_driver_library` option?

---

<div class="post-metadata">

**Author:** ![ajay\_shanker](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@ajay\_shanker](https://discuss.elastic.co/u/ajay_shanker)\
**Post date:** [September 21, 2016, 4:20am UTC](https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004/3 "2016-09-21T04:20:53Z")

</div>

Thanks Magnus for quick reply.  
My problem is solved and i replaced postgresql to mysql library

# file: simple-out.conf

input {  
jdbc {  
jdbc\_driver\_library =\> "C:/logstash/lib/mysql-connector-java-5.1.38-bin.jar"  
jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
jdbc\_connection\_string =\> "jdbc:mysql://127.0.0.1:3306/lenderplatform\_dev"  
jdbc\_user =\> "root"  
jdbc\_password =\> ""  
statement =\> "SELECT \* FROM lenderplatform\_dev.loans"  
jdbc\_paging\_enabled =\> "true"  
jdbc\_page\_size =\> "50000"  
}  
}  
output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "lenderplatform\_dev"  
document\_type =\> "loans"  
}  
stdout { codec =\> json\_lines }  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:37am UTC](https://discuss.elastic.co/t/how-to-connect-mysql-database-by-logstash/61004/4 "2017-07-06T04:37:41Z")

</div>


