日常有用: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);

 

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