Mysql库表数据随时从生产拉取到数仓(Mysql)的方案(3)

来源:互联网 发布:gif动态制作软件 编辑:程序博客网 时间:2024/06/06 01:49
本篇主要是接上文【Mysql库表数据随时从生产拉取到数仓(Mysql)的方案(2)】-->http://blog.csdn.net/babyfish13/article/details/53705454,及【Mysql库表数据随时从生产拉取到数仓(Mysql)的方案(3)】-->http://blog.csdn.net/babyfish13/article/details/53705729;具体说明Mysql从生产上的分表传输数据到数仓的合表的过程。
事实上,如果Mysql上采用分表处理了,数据量一般就很大了;即使在一个新库上将其合成一张表,Mysql也是支撑不了的;所以,这样的情况,还是要考虑Hadoop进行处理比较合适。
1、程序目录路径
[root@slave1 AllInOne]# pwd/root/AllInOne[root@slave1 AllInOne]# tree.├── data└── etl_script    ├── nohup.out    └── user_profile.sh2 directories, 2 files[root@slave1 AllInOne]#

2、程序样例
[root@slave1 etl_script]# cat user_profile.sh #!/bin/bashrm -rf /root/AllInOne/data/jellyfish_user.user_profile.dat/usr/bin/mysql -h121.121.121.159 -P50514 -uhadoop -psrcpasswd -N -e"select table_name from information_schema.tables where table_schema='jellyfish_user' and table_name like 'user_profile%';" > /root/AllInOne/data/jellyfish_user.user_profile.listi=1for tab in $(cat /root/AllInOne/data/jellyfish_user.user_profile.list)docol_num=$itab_name=$(awk -F "|" 'NR=='$col_num' {print $1}'  /root/AllInOne/data/jellyfish_user.user_profile.list)echo $tab_name#user_profile data proc .../usr/bin/mysql -h121.121.121.159 -P50514 -uhadoop -psrcpasswd -N -e"set character_set_results=utf8;select CONCAT(ifnull(\`uid\`,''),'|',ifnull(\`nickname\`,''),'|',ifnull(\`avatar\`,''),'|',ifnull(\`signature\`,''),'|',ifnull(\`gender\`,''),'|',ifnull(\`type\`,''),'|',ifnull(\`source\`,''),'|',ifnull(\`phone_num_verified\`,''),'|',ifnull(\`id_card_verified\`,''),'|',ifnull(\`state\`,''),'|',ifnull(\`last_login_time\`,''),'|',ifnull(\`created_time\`,''),'|',ifnull(\`updated_time\`,'')) from jellyfish_user.$tab_name;" >> /root/AllInOne/data/jellyfish_user.user_profile.dat: $(( i++ ))done/usr/bin/mysql -h192.168.16.71 -uroot -p123 -e "set character_set_results=utf8;use AllInOne;truncate table user_profile;load data local infile '/root/AllInOne/data/jellyfish_user.user_profile.dat' into table user_profile character set utf8 fields terminated by '|' enclosed by '' lines terminated by '\n' ignore 0 lines;"[root@slave1 etl_script]# 

3、源字段的获取Sql
select CONCAT('CONCAT(',GROUP_CONCAT(concat('ifnull(\\`',b.COLUMN_NAME,'\\`,\'\')',',\'|\'')),')')from information_schema.`TABLES` a left join information_schema.`COLUMNS` b on a.TABLE_NAME=b.TABLE_NAME and a.TABLE_SCHEMA=b.TABLE_SCHEMAwhere a.table_NAME='user_profile';


此并非一个自动化的方案,如有需要可进行手工复制和更改。
发现之前总结过了,见[使用Shell进行Mysql间数据以文本形式传输及注意事项]-->http://blog.csdn.net/babyfish13/article/details/53510301
那一篇说的更细一些,可参考过去。
0 0
原创粉丝点击