大数据项目-金融审批实时数据仓库-动态维护维度表:创建数据库、表、开启binlog、测试kafka

提示

下面操作,没有特殊说明,都是登录 hadoop1 进行操作

创建数据库、表

执行下面命令:

mysql -uroot -proot -e"create database financial_lease_config charset utf8mb4 collate utf8mb4_general_ci"

创建表

登录 hadoop1,在 financial_lease_config 库中创建配置表 table_process:

DROP TABLE IF EXISTS `table_process`;
CREATE TABLE `table_process` (
    `source_table` varchar(200) NOT NULL COMMENT '来源表',
    `sink_table` varchar(200) NOT NULL COMMENT '输出表',
    `sink_family` varchar(200) COMMENT '输出到 hbase 的列族',
    `sink_columns` varchar(2000) COMMENT '输出字段',
    `sink_row_key` varchar(200) COMMENT 'rowkey',
    PRIMARY KEY (`sink_table`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

开启Binlog

指定 financial_lease_config 数据库发生数据变化时,会生成 binlog 日志

编辑 MySQL 配置文件:

vim /etc/my.cnf

最下面增加:

binlog-do-db=financial_lease_config

重启

systemctl restart mysql

警告1

如果已经启动 maxwell,重启 MySQL 后,maxwell会停掉

报错

由于增加 binlog 配置,再次启动 maxwell,一般会成功,但 financial_lease_config 数据库中数据发生变化时,会报错退出

详见:
https://www.malaoshi.top/show_1GW1f2HsgZlt.html

解决

将 MySQL 中 maxwell 数据库中的 所有表全部删除,再次启动 maxwell 即可

启动命令详见:
https://www.malaoshi.top/show_1GW1eSMfUME7.html

启动kafka消费者

查看当配置表发生变化时,是否能够采集到

kafka-console-consumer.sh --bootstrap-server hadoop1:9092 --topic fl-db

插入数据

向 table_process 表中插入 维度表 的配置信息

INSERT INTO `table_process`(`source_table`, `sink_table`, `sink_family`, `sink_columns`, `sink_row_key`) VALUES 
('business_partner', 'dim_business_partner', 'info', 'id,create_time,update_time,name', 'id'),
('department', 'dim_department', 'info', 'id,create_time,update_time,department_level,department_name,superior_department_id', 'id'),
('employee', 'dim_employee', 'info', 'id,create_time,update_time,name,type,department_id', 'id'),
('industry', 'dim_industry', 'info', 'id,create_time,update_time,industry_level,industry_name,superior_industry_id', 'id');

kafka测试结果

可以看到kafka消费者打印的数据:

说明成功


原文出处:/show_1GW1eu4K8MKN.html