hdfs hive mqsql之间的导入语句

hive建表

hive> 
create table hivetest.flow(
phoneNumber string,
upflow int,
downflow int)
row format DELIMITED FIELDS TERMINATED BY ' ' //读取文件分隔符
STORED AS TEXTFILE
tblproperties("skip.header.line.count"="1");//忽略文件第一行

hdfs 导入hive(方便MapReduce查询)

load data  inpath '/input/user_log.scv' into table hivetest.userlog;

hive 导入hdfs(查询结果导出到hdfs)

insert overwrite directory '/output/t_userlog'  //目标路径
row format DELIMITED FIELDS TERMINATED BY '\t'  	      //分隔符对应hdfs -mysql
STORED AS TEXTFILE 
SELECT * FROM hivetest.userlog 			//sql

hdfs -mysql(存入数据库)

sqoop export --connect 'jdbc:mysql://ETC01:3306/test?
useUnicode=true&characterEncoding=utf-8'  	//防止中文乱码
--username root --password root  --table userlog  //目标表
--direct  //方言 加快读取速度
--export-dir /output/t_userlog   		//源目录
--driver com.mysql.jdbc.Driver 
--input-fields-terminated-by '\t' --lines-terminated-by '\n'  //分隔符对应hdfs 导入hive

mysql–hive

sqoop import  --connect jdbc:mysql://ETC01:3306/test --username root  --password root 
--table math --hive-import 
--hive-database hivetest --hive-table math 
--delete-target-dir  --target-dir  /input/sqoop/tmp -m 1

1.–append 追加
2.–as -textfile 作为普通文件导入
3.–columns 导入列
4.–target-dir 目标
5.–delete–target-dir 删除目录

(1) query, where子句必须有$CONDITIONS(固定写法)

sqoop import 
--connect jdbc:mysql://ETC01:3306/test 
--username root 
--password root 
--query 'select * from student where id>10 and $CONDITIONS'  
--delete-target-dir 
--target-dir  /input/sqoop/student 
--split-by id (无主键)  -m1

(2)columns指定导入的字段

--table user 
--columns account,password  //不能有空格

(3)where子句

--table user 
--where 'id > 5 and account like "f%"' 

(4)hive建表语句中不能有分隔符,否则可能mysql 表中数据都导入到一列中
(5)源表中无主键用 -m 1


退出安全模式

hdfs dfsadmin -safemode leave

远程连接

nohup hive --service hiveserver2 -hiveconfhive.server2.thrift.port=10010 &

删除文件第一行

sed -i‘1d’ samll.txt 

忽略文件第一行

  tblproperties("skip.header.line.count"="1");
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值