NIFI1.21.0_Postgresql和Mysql同时指定库_指定多表_全量同步到Mysql数据库以及Hbase数据库中---大数据之Nifi工作笔记0060
    		       		warning:
    		            这篇文章距离上次修改已过424天,其中的内容可能已经有所变动。
    		        
        		                
                在Apache NiFi中,要实现PostgreSQL和MySQL数据库的同步,并指定库、指定多表进行全量同步,可以使用NiFi的处理器如ExecuteSQL来执行SQL语句,并使用PutMysql或PutDatabaseRecord等处理器将数据同步到MySQL。
以下是一个基本的流程示例:
- 使用ExecuteSQL处理器从PostgreSQL读取数据。
- 使用ConvertRecord处理器进行数据类型转换,以适应MySQL的数据格式。
- 使用PutMysql或PutDatabaseRecord处理器将数据写入MySQL。
确保在PostgreSQL和MySQL中配置了正确的HBA(host-based authentication),以允许NiFi服务器进行连接。
以下是一个简化的NiFi模板,展示了如何从PostgreSQL读取数据并同步到MySQL:
<?xml version="1.0" encoding="UTF-8"?>
<template>
  <processors>
    <id>1</id>
    <parentGroupId>2</parentGroupId>
    <position>
      <x>0</x>
      <y>0</y>
    </position>
    <bundle>
      <group>org.apache.nifi</group>
      <artifact>nifi-standard-processors</artifact>
      <version>1.21.0</version>
    </bundle>
    <type>org.apache.nifi.processors.standard.ExecuteSQL</type>
    <config>
      <!-- 配置PostgreSQL连接 -->
      <property>
        <name>Database Connection Pool Name</name>
        <value>PostgreSQL Connection Pool</value>
      </property>
      <property>
        <name>SQL Script</name>
        <value>SELECT * FROM your_table1; SELECT * FROM your_table2;</value>
      </property>
      <!-- 其他配置... -->
    </config>
  </processors>
  <processors>
    <id>2</id>
    <parentGroupId>3</parentGroupId>
    <position>
      <x>0</x>
      <y>0</y>
    </position>
    <bundle>
      <group>org.apache.nifi</group>
      <artifact>nifi-standard-processors</artifact>
      <version>1.21.0</version>
    </bundle>
    <type>org.apache.nifi.processors.standard.PutDatabaseRecord</type>
    <config>
      <!-- 配置MySQL连接 -->
      <property>
        <name>Controller Service</name>
        <value>Database Connection Pool for MySQL</value>
      </property>
      <property>
        <name>Table Name</name>
        <value>your_table1</value>
      </property>
      <!-- 其他配置... -->
    </config>
  </processors>
  <connections>
    <id>1</id>
    <source>
      <id>1</id>
      <groupId>2</groupId>
    </source>
    <destination>
      <id>2</id>
      <groupId>3</groupId>
    </destination>
  </connections>
  <controllerServices>
    <id>1</id>
    <bundle>
      <group>org.apache.nifi</group>
      <artifact>nifi-database-bundle</artifact>
      <version>1.21.0</version>
    </bundle>
    <type>org.apac
评论已关闭