2.配置文件

在Flume的conf文件夹下,新建一个名为mysql.conf的配置文件,内容如下:

Name the components on this agent

mysql.sources = mysql-source mysql.sinks = loggerSink mysql.channels = memoryChannel

Describe/configure the source

mysql.sources.mysql-source.type = org.apache.flume.source.jdbc.JdbcSource mysql.sources.mysql-source.driver = com.mysql.jdbc.Driver mysql.sources.mysql-source.url = jdbc:mysql://localhost:3306/school mysql.sources.mysql-source.user = root mysql.sources.mysql-source.password = 123456 mysql.sources.mysql-source.table = student mysql.sources.mysql-source.columns.to.select = id, name, age, grade mysql.sources.mysql-source.batch.size = 1000

Describe the sink

mysql.sinks.loggerSink.type = logger

Use a channel which buffers events in memory

mysql.channels.memoryChannel.type = memory mysql.channels.memoryChannel.capacity = 10000 mysql.channels.memoryChannel.transactionCapacity = 1000

Bind the source and sink to the channel

mysql.sources.mysql-source.channels = memoryChannel mysql.sinks.loggerSink.channel = memoryChannel

3.启动Flume

在Flume的bin文件夹下,使用以下命令启动Flume:

./flume-ng agent -n mysql -c conf -f conf/mysql.conf -Dflume.root.logger=INFO,console

4.查看数据

在Kafka消费者中,查看相应数据。可以看到输出了student表中的内容:

1 Xiaoming 23 98 2 Zhangsan 24 96 3 Lisi 24 93 4 Wangwu 21 91 5 Weiliu 21 91

至此,MySQL数据的Flume输出完成

1.MySQL数据输出在MySQL中建立数据库school在数据库中建立表student。SQL语句如下:create database school;use school;create table studentid int not nullname varchar40age intgrade intprimary keyid; 编写配置文件将student表中的内容输出到控制台。启动

原文地址: https://www.cveoy.top/t/topic/hvkc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录