<tfoot id='YoCcy'></tfoot>

    <small id='YoCcy'></small><noframes id='YoCcy'>

      <bdo id='YoCcy'></bdo><ul id='YoCcy'></ul>

  1. <i id='YoCcy'><tr id='YoCcy'><dt id='YoCcy'><q id='YoCcy'><span id='YoCcy'><b id='YoCcy'><form id='YoCcy'><ins id='YoCcy'></ins><ul id='YoCcy'></ul><sub id='YoCcy'></sub></form><legend id='YoCcy'></legend><bdo id='YoCcy'><pre id='YoCcy'><center id='YoCcy'></center></pre></bdo></b><th id='YoCcy'></th></span></q></dt></tr></i><div id='YoCcy'><tfoot id='YoCcy'></tfoot><dl id='YoCcy'><fieldset id='YoCcy'></fieldset></dl></div>
    1. <legend id='YoCcy'><style id='YoCcy'><dir id='YoCcy'><q id='YoCcy'></q></dir></style></legend>
    2. 如何将 mysql 数据库同步到外部数据源

      How to sync a mysql database to external data source(如何将 mysql 数据库同步到外部数据源)

      <small id='GZ88h'></small><noframes id='GZ88h'>

      <tfoot id='GZ88h'></tfoot><legend id='GZ88h'><style id='GZ88h'><dir id='GZ88h'><q id='GZ88h'></q></dir></style></legend>
        • <bdo id='GZ88h'></bdo><ul id='GZ88h'></ul>

                <tbody id='GZ88h'></tbody>
                <i id='GZ88h'><tr id='GZ88h'><dt id='GZ88h'><q id='GZ88h'><span id='GZ88h'><b id='GZ88h'><form id='GZ88h'><ins id='GZ88h'></ins><ul id='GZ88h'></ul><sub id='GZ88h'></sub></form><legend id='GZ88h'></legend><bdo id='GZ88h'><pre id='GZ88h'><center id='GZ88h'></center></pre></bdo></b><th id='GZ88h'></th></span></q></dt></tr></i><div id='GZ88h'><tfoot id='GZ88h'></tfoot><dl id='GZ88h'><fieldset id='GZ88h'></fieldset></dl></div>
              • 本文介绍了如何将 mysql 数据库同步到外部数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个名为 search 的 mysql 数据库表,我需要用 ElasticSearch 索引跟上数据.我已经将表从表导出到 es 索引,但现在我需要保持数据同步,否则搜索将很快变得陈旧.

                I have a mysql database table called search that I need to keep up to data with an ElasticSearch index. I have already exported the table from the table to the es index, but now I need to keep the data in sync or else the search will become stale quite quickly.

                我能想到的唯一方法是每 x 分钟导出一次表,然后将其与上次导入的内容进行比较.这是不可行的,因为该表有大约 10M 行,我不想整天每五分钟进行一次表导出.对此有什么好的解决方案?请注意,我只有对数据库的读取权限.

                The only way I can think of is by exporting the table every x minutes and then comparing it with what was last imported. This isn't feasible since the table has about 10M rows and I don't want to be doing table exports every five minutes all day long. What would be a good solution for this? Note that I only have read-access to the database.

                推荐答案

                我会利用 Logstash 和 jdbc input 插件和一个 elasticsearch 输出 插件.有一篇博客文章 展示了此解决方案的完整示例.

                I would leverage Logstash with a jdbc input plugin and an elasticsearch output plugin. There's a blog article showing a full example of this solution.

                安装 Logstash 后,您可以使用我上面提到的插件创建一个配置文件,如下所示:

                After installing Logstash, you can create a configuration file with the plugins I mentioned above like this:

                input {
                    jdbc {
                        jdbc_connection_string => "jdbc:mysql://localhost:3306/mydb"
                        jdbc_user => "user"
                        jdbc_password => "1234"
                        jdbc_validate_connection => true
                        jdbc_driver_library => "mysql-connector-java-5.1.36-bin.jar"
                        jdbc_driver_class => "com.mysql.jdbc.Driver"
                        schedule => "5m"
                        statement => "SELECT * FROM search WHERE timestamp > :sql_last_value"
                    }
                }
                output {
                    elasticsearch {
                        protocol => http
                        index => "searches"
                        document_type => "search"
                        document_id => "%{uid}"
                        host => "ES_NODE_HOST"
                    }
                }
                

                您需要确保更改一些值以匹配您的环境,但这对于您需要执行的操作应该没有问题.

                You need to make sure to change a few values to match your environment, but this should work out without a problem for what you need to do.

                查询将每 5 分钟运行一次,并将获取所有 search 记录,其 timestamp(更改该名称以匹配您的数据)比上次查询更新跑了.选定的记录将沉没在位于 ES_NODE_HOST 上的 Elasticsearch 服务器中的 searches 索引中.确保相应地更改索引和类型名称,以及主键字段的名称(即 uid)以匹配您的数据.

                Every 5 minutes the query will run and will fetch all search records whose timestamp (change that name to match your data) is more recent than the last time the query ran. The selected records will be sinked in the searches index located in your Elasticsearch server on ES_NODE_HOST. Make sure to change the index and type name accordingly, as well as the name of the primary key field (i.e. uid) to match your data as well.

                这篇关于如何将 mysql 数据库同步到外部数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Building a comma separated list?(建立一个逗号分隔的列表?)
                Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  <tbody id='IrpCE'></tbody>

                  <bdo id='IrpCE'></bdo><ul id='IrpCE'></ul>
                      <legend id='IrpCE'><style id='IrpCE'><dir id='IrpCE'><q id='IrpCE'></q></dir></style></legend>

                      1. <tfoot id='IrpCE'></tfoot>
                      2. <i id='IrpCE'><tr id='IrpCE'><dt id='IrpCE'><q id='IrpCE'><span id='IrpCE'><b id='IrpCE'><form id='IrpCE'><ins id='IrpCE'></ins><ul id='IrpCE'></ul><sub id='IrpCE'></sub></form><legend id='IrpCE'></legend><bdo id='IrpCE'><pre id='IrpCE'><center id='IrpCE'></center></pre></bdo></b><th id='IrpCE'></th></span></q></dt></tr></i><div id='IrpCE'><tfoot id='IrpCE'></tfoot><dl id='IrpCE'><fieldset id='IrpCE'></fieldset></dl></div>

                        <small id='IrpCE'></small><noframes id='IrpCE'>