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");