Hive导出数据到MYSQL . 笔记

 1.

vim export.sql:

SELECT
IF(player_id is not NULL,player_id,'  '),
IF(regist_time is not NULL,regist_time,0),
IF(online_time_num is not NULL,online_time_num,0),
IF(last_login_time is not NULL,last_login_time,0),
IF(last_login_ip is not NULL,last_login_ip,'0.0.0.0'),
IF(`level` is not NULL,`level`,0),
IF(coin is not NULL,coin,0),
IF(game_id is not NULL,game_id,0),
IF(agent_id is not NULL,agent_id,0),
IF(server_id is not NULL,server_id,0),
IF(`date` is not NULL,`date`,'0000-00-00'),
IF(`name` is not NULL,`name`,'  ')
FROM fycenter.members
WHERE (
(`date`='2012-03-01' AND game_id=5 AND agent_id IN (135,127) )
OR (`date`='2012-02-29' AND game_id=6 AND agent_id IN (173,184) )
OR (`date`='2012-02-29' AND game_id=7 AND agent_id IN (329, 337,331) )
OR (`date`='2012-02-29' AND game_id=10 AND agent_id = 282)
OR (`date`='2012-02-29' AND game_id=12 AND agent_id IN (217,213) )
OR (`date`='2012-02-29' AND game_id=13 AND agent_id=370)
OR (`date`='2012-02-29' AND game_id=3)




2. 命令行下执行:
/opt/hive/bin/hive -f export.sql > export.result2.txt


cp export.result2.txt > /tmp/export.result2.txt


mysql -uroot -pxxx123 olap -hxxx.xxx.xxx.xxx

清空表
> truncate table members;
> Load data infile '/tmp/export.result2.txt' Into table members    (    ) ;

你可能感兴趣的:(Hive导出数据到MYSQL . 笔记)