日常有用:hive数据导入到mysql小记

1、hive数据导入成竖线分隔符格式数据

hive -e "select concat(ip,'|',
location,'|',
is_kuandai,'|',
ban_status,'|',
is_blacklist,'|',
ban_type,'|',
ban_timelong,'|',
unban_count,'|',
remark,'|',
remark_detail,'|',
create_time,'|',
update_time,'|',
dt)
from risk.risk_abnormal_iplocation_full_1d">risk_abnormal_iplocation_full_1d.txt;

2、装载hive导出的数据

注意:
取其中某些字段列,设定格式是竖线分隔符。

LOAD DATA LOCAL INFILE '/home/hadoop/nisj/tmp/risk_abnormal_iplocation_full_1d.txt' INTO TABLE thanos.risk_abnormal_iplocation_full_1d fields terminated by '|' (ip,
location,
is_kuandai,
ban_status,
is_blacklist,
ban_type,
ban_timelong,
unban_count,
remark,
remark_detail,
create_time,
update_time,
dt) ;

3、local_infile开关打开

若出现错误显示  ERROR 1148 (42000): The used command is not allowed with this MySQL version
原因:local_infile变量处于OFF  需要手动将其置于ON
mysql> SET GLOBAL local_infile=1;

-------------------------------------------------------------------------------------------------------------------------------
另一个完整实例:

hive -e "select concat(userinfo_id,'|',
device_id,'|',
ip,'|',
consignee_address,'|',
full_address,'|',
dt)
from risk.risk_cheat_bot_address_incr_1d">risk_cheat_bot_address_incr_1d.txt

LOAD DATA LOCAL INFILE '/home/hadoop/nisj/tmp/risk_cheat_bot_address_incr_1d.txt' INTO TABLE thanos.risk_cheat_bot_address_incr_1d fields terminated by '|' (userinfo_id,
device_id,
ip,
consignee_address,
full_address,
dt);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章