# Unable to connect mysql using logstash

**URL:** <https://discuss.elastic.co/t/unable-to-connect-mysql-using-logstash/238969>\
**Category:** Logstash\
**Created:** [June 27, 2020, 6:24pm UTC](https://discuss.elastic.co/t/unable-to-connect-mysql-using-logstash/238969 "2020-06-27T18:24:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandy1](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@sandy1](https://discuss.elastic.co/u/sandy1)\
**Post date:** [June 27, 2020, 6:24pm UTC](https://discuss.elastic.co/t/unable-to-connect-mysql-using-logstash/238969/1 "2020-06-27T18:24:32Z")

</div>

logstash.config:  
\> input {  
\> jdbc {  
\> jdbc\_connection\_string =\> "jdbc:mysql://localhost:3306/db\_name?ssl=false"  
\> jdbc\_user =\> "admin"  
\> jdbc\_password =\> "password"  
\> jdbc\_driver\_library =\> "D:/elk/mysql-connector-java-5.1.47.jar"  
\> jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
\> statement =\> "SELECT \* FROM Users"  
\> use\_column\_value =\> true  
\> tracking\_column =\> id  
\> tracking\_column\_type =\> "numeric"  
\>  
\> }  
\> }  
\> output {  
\> stdout { codec =\> json\_lines }  
\> elasticsearch {  
\> "hosts" =\>"localhost:9200"  
\> "index" =\> "xyz"  
\> "document\_type" =\> "data"  
\>  
\> }  
\>  
\> }

Output:  
D:\elk\logstash-5.6.3\bin\>logstash -f logstash-config.conf  
Sending Logstash's logs to D:/elk/logstash-5.6.3/logs which is now configured via log4j2.properties  
[2020-06-27T10:54:04,431][INFO][logstash.modules.scaffold] Initializing module {:module\_name=\>"fb\_apache", :directory=\>"D:/elk/logstash-5.6.3/modules/fb\_apache/configuration"}  
[2020-06-27T10:54:04,436][INFO][logstash.modules.scaffold] Initializing module {:module\_name=\>"netflow", :directory=\>"D:/elk/logstash-5.6.3/modules/netflow/configuration"}  
[2020-06-27T10:54:05,415][INFO][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=\>{:removed=\>, :added=\>[[http://localhost:9200/](http://localhost:9200/)]}}  
[2020-06-27T10:54:05,418][INFO][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck\_url=\>[http://localhost:9200/](http://localhost:9200/), :path=\>"/"}  
[2020-06-27T10:54:05,564][WARN][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=\>"[http://localhost:9200/](http://localhost:9200/)"}  
[2020-06-27T10:54:05,613][INFO][logstash.outputs.elasticsearch] Using mapping template from {:path=\>nil}  
[2020-06-27T10:54:05,618][INFO][logstash.outputs.elasticsearch] Attempting to install template {:manage\_template=\>{"template"=\>"logstash-_", "version"=\>50001, "settings"=\>{"index.refresh\_interval"=\>"5s"}, "mappings"=\>{"default"=\>{"\_all"=\>{"enabled"=\>true, "norms"=\>false}, "dynamic\_templates"=\>[{"message\_field"=\>{"path\_match"=\>"message", "match\_mapping\_type"=\>"string", "mapping"=\>{"type"=\>"text", "norms"=\>false}}}, {"string\_fields"=\>{"match"=\>"_", "match\_mapping\_type"=\>"string", "mapping"=\>{"type"=\>"text", "norms"=\>false, "fields"=\>{"keyword"=\>{"type"=\>"keyword", "ignore\_above"=\>256}}}}}], "properties"=\>{"@timestamp"=\>{"type"=\>"date", "include\_in\_all"=\>false}, "@version"=\>{"type"=\>"keyword", "include\_in\_all"=\>false}, "geoip"=\>{"dynamic"=\>true, "properties"=\>{"ip"=\>{"type"=\>"ip"}, "location"=\>{"type"=\>"geo\_point"}, "latitude"=\>{"type"=\>"half\_float"}, "longitude"=\>{"type"=\>"half\_float"}}}}}}}}  
[2020-06-27T10:54:05,625][INFO][logstash.outputs.elasticsearch] New Elasticsearch output {:class=\>"LogStash::Outputs::ElasticSearch", :hosts=\>["[//localhost:9200](https://localhost:9200)"]}  
[2020-06-27T10:54:05,632][INFO][logstash.pipeline] Starting pipeline {"id"=\>"main", "pipeline.workers"=\>4, "pipeline.batch.size"=\>125, "pipeline.batch.delay"=\>5, "pipeline.max\_inflight"=\>500}  
[2020-06-27T10:54:05,923][INFO][logstash.pipeline] Pipeline main started  
[2020-06-27T10:54:06,079][INFO][logstash.agent] Successfully started Logstash API endpoint {:port=\>9600}  
[2020-06-27T10:54:49,378][ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error\_message=\>"Java::ComMysqlJdbcExceptionsJdbc4::CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."}  
[2020-06-27T10:54:49,384][WARN][logstash.inputs.jdbc] Exception when executing JDBC query {:exception=\>#\<Sequel::DatabaseConnectionError: Java::ComMysqlJdbcExceptionsJdbc4::CommunicationsException: Communications link failure

```
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.>}
[2020-06-27T10:54:49,387][WARN][logstash.inputs.jdbc] Attempt reconnection.
[2020-06-27T10:54:57,876][WARN][logstash.runner] SIGINT received. Shutting down the agent.
[2020-06-27T10:54:57,906][WARN][logstash.agent] stopping pipeline {:id=>"main"}
[2020-06-27T10:54:58,241][FATAL][logstash.runner] SIGINT received. Terminating immediately..
Terminate batch job (Y/N)?
^C
D:\elk\logstash-5.6.3\bin>
```

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [June 28, 2020, 3:19am UTC](https://discuss.elastic.co/t/unable-to-connect-mysql-using-logstash/238969/2 "2020-06-28T03:19:49Z")

</div>

This seems to be more of [general problem](https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql) between jdbc client mysql server .

Are you able to connect to your mysql at first place ?

`mysql --host localhost --port 3306 --user admin --password`

---

<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 26, 2020, 3:26am UTC](https://discuss.elastic.co/t/unable-to-connect-mysql-using-logstash/238969/3 "2020-07-26T03:26:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
