整理一下,用的时候照着贴就行了。
1.hive数据导出
将select的结果放到本地文件系统中
INSERT OVERWRITE LOCAL DIRECTORY '/tmp/reg_3' SELECT a.* FROM events a;
将select的结果放到hdfs文件系统中
INSERT OVERWRITE DIRECTORY '/tmp/hdfs_out' SELECT a.* FROM table_name a WHERE a.ds='<DATE>';
2.hive数据导入
LOAD DATA [LOCAL] INPATH ‘/data/userdata’ [OVERWRITE] INTO TABLE user;
#创建表的时候直接指定路径
CREATE EXTERNAL TABLE page_view(viewTime INT, userid BIGINT,
page_url STRING, referrer_url STRING,
ip STRING COMMENT 'IP Address of the User',
country STRING COMMENT 'country of origination')
COMMENT 'This is the staging page view table'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LINES TERMINATED BY '\002'
STORED AS TEXTFILE
年限LOCATION '/user/data/staging/page_view'; #创建表之后也可以导入数据到表中
#本机路径
LOAD DATA LOCAL INPATH '/tmp/date.txt' OVERWRITE INTO TABLE page_view PARTITION(pt='2008-06-08')
#Hadoop路径
LOAD DATA INPATH `/tmp/date.txt` OVERWRITE INTO TABLE page_view PARTITION(pt='2008-06-08')
#添加一个分区到表
ALTER TABLE tmp_xx ADD PARTITION (pt='100610') location '/group/mywork/hive/xx/pt=100610' ;
3.删除分区
alter table test drop partition (birth='1980',age='30');
4.日志
hive -hiveconf hive.root.logger=INFO,console
hive --service hiveserver -p 10000 &
hive --service hiveserver2 &
SET hive.exec.compress.output=true;
SET mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
set hive.exec.dynamic.partition.mode=nonstrict;
ALTER TABLE day_table ADD PARTITION (dt='2008-08-08', hour='08') location '/path/pv1.txt'
5.配置数据库,及授权
配置metastore
create database metastore DEFAULT CHARACTER SET utf8;
GRANT all ON metastore.* TO hive@"172.20.0.63" identified by "hive";
FLUSH PRIVILEGES;
6.配置java jdbc
sudo yum install mysql-connector-java
ln -s /usr/share/java/mysql-connector-java.jar /usr/lib/hive/lib/mysql-connector-java.jar
7.beeline
/usr/lib/hive/bin/beeline
!connect jdbc:hive2://172.20.0.12:10000/test;principal=hive/
[email protected]
8.hive jdbc测试
java -cp $CLASSPATH:hivejdbc.jar:/usr/lib/hive/lib/hive-metastore-0.12.0-cdh5.0.2.jar:/usr/lib/hive/lib/antlr-runtime-3.4.jar:/usr/java/jdk1.7.0_45-cloudera/db/lib/derby.jar:/usr/lib/hadoop-0.20-mapreduce/hadoop-core-2.3.0-mr1-cdh5.0.2.jar:/usr/lib/hive/lib/hive-exec-0.12.0-cdh5.0.2.jar:/usr/lib/hive/lib/hive-jdbc-0.12.0-cdh5.0.2.jar:/usr/lib/hive/lib/libthrift-0.9.0.cloudera.2.jar:/usr/lib/hive/lib/libfb303-0.9.0.jar:/usr/lib/hive/lib/hive-service-0.12.0-cdh5.0.2.jar:/usr/lib/hive/lib/slf4j-api-1.7.5.jar:/usr/lib/impala/lib/slf4j-log4j12-1.6.1.jar:/usr/lib/hive/lib/httpcore-4.2.5.jar:/usr/lib/hive/lib/httpclient-4.2.5.jar:/usr/lib/hadoop/lib/commons-configuration-1.6.jar:/usr/lib/hadoop/hadoop-common-2.3.0-cdh5.0.2.jar:/usr/lib/hbase/lib/commons-logging-1.1.1.jar:/usr/lib/hadoop/lib/log4j-1.2.17.jar:/usr/lib/hadoop/lib/commons-collections-3.2.1.jar:/usr/lib/hadoop/hadoop-auth.jar test.HiveJDBC