让ElasticSearch连接mysql数据库
2013-08-21 17:02
113 查看
https://github.com/jprante/elasticsearch-river-jdbc/wiki/Quickstart
Prerequisites:
A running MySQL database
A terminal / console with commands
Internet access (of course)
http://elasticsearch.org) from
Quickstart
Quickstart
A short guide for the impatient!Prerequisites:
A running MySQL database
test, with user
testand password
test, a table
orders
A terminal / console with commands
curland
unzip
Internet access (of course)
Let's go!
Download elasticsearch (current version is 0.19.8, check for the most recent version onhttp://elasticsearch.org) from
curl -OL https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.10.zip[/code]
Unpack zip file into you favorite elasticsearch directory, we call it $ES_HOMEcd $ES_HOMEunzip path/to/elasticsearch-0.19.10.zip
Install JDBC river plugin (current version is 1.3.2, check for the most recent version, and if you have the file permissions to write into thepluginsfolder). If you have installed a JDBC river plugin before, it is recommended to remove the folderplugins/river-jdbcbefore installing a new version. (**Note**: If you're using a version of elasticsearch >= 0.90.0, you need to use at least version 2.2.0 of the river-jdbc plugin)../bin/plugin --url http://bit.ly/10FJhEd -install river-jdbc
Download MySQL JDBC driver (current version is 5.1.21, check for the most recent version)curl -OL http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.21.zip/from/http://cdn.mysql.com/[/code]
Add MySQL JDBC driver jar to JDBC river plugin directorycp mysql-connector-java-5.1.21-bin.jar $ES_HOME/plugins/river-jdbc/
Start elasticsearch in terminal window with logging on the console./bin/elasticsearch -f
Start another terminal window, and create a new JDBC river with namemy_jdbc_riverwith thiscurlcommandcurl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{ "type" : "jdbc", "jdbc" : { "driver" : "com.mysql.jdbc.Driver", "url" : "jdbc:mysql://localhost:3306/test", "user" : "test", "password" : "test", "sql" : "select * from orders" }, "index" : { "index" : "jdbc", "type" : "jdbc" } }'
The river runs! Watch the log on the elasticsearch console for the river activity. When the river fetched the data and is going to wait for the next cycle (which is by default 60 minutes ahead), you can query your elasticsearch node for the data you just
indexed with the followingcurlcommandcurl -XGET 'localhost:9200/jdbc/jdbc/_search?pretty&q=*'
Enjoy the result!
If you want to stop themy_jdbc_riverriver fetching data from theorderstable after the quick demonstration, use thiscurlcommand:curl -XDELETE 'localhost:9200/_river/my_jdbc_river'What next?
Now, if you want more fine-tuning, you can drop the indexjdbc, change the mapping, change the index name or type name, change the river creation settings, play with the data fetch interval - whatever you like.
相关文章推荐
- c/c++连接mysql数据库
- python3.5连接mysql数据库
- 轻松应对JSP连接MySQL数据库问题
- python连接mysql数据库
- Mysql数据库远程连接10038报错问题原因及解决方案
- java连接mysql数据库
- 用ADO 连接mysql数据库的方法
- Excel连接到MySQL数据库实操演示
- eclipse使用JDBC连接mysql数据库
- java直接连接mysql数据库
- 使用code blocks连接mysql数据库的方法
- JDBC连接MySQL数据库及演示样例
- MySQL数据库的连接
- asp.net连接mysql数据库小例
- JDBC连接MYSQL数据库
- Navicat for mysql 远程连接 mySql数据库10061、1045错误问题
- Java连接MYSQL数据库的详细步骤
- php入门之连接mysql数据库的一个类
- Java连接MySql数据库警告:Establishing SSL connection without server's identity verification is not recommend
- Java 连接MySql数据库