1
2
3
|
mysql> create database hive;
mysql> grant all on *.* to
'hive'
@
'%'
identified by
'hive'
;
mysql> flush privileges;
|
1
2
|
# tar zxvf apache-hive-1.2.0-bin.tar.gz
# mv apache-hive-1.2.0-bin /opt
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# vi hive-site.xml
<configuration>
<!--以下是MySQL连接信息-->
<property>
<name>javax.jdo.option.ConnectionURL<
/name
>
<value>jdbc:mysql:
//192
.168.18.210:3306
/hive
?createDatabaseIfNotExist=
true
<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionDriverName<
/name
>
<value>com.mysql.jdbc.Driver<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionUserName<
/name
>
<value>hive_user<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionPassword<
/name
>
<value>hive_pass<
/value
>
<
/property
>
<
/configuration
>
|
1
2
3
4
5
|
# vi /etc/profile
HIVE_HOME=
/opt/apache-hive-1
.2.0-bin
PATH=$PATH:$HIVE_HOME
/bin
export
HIVE_HOME PATH
# source /etc/profile
|
1
|
# hive --service metastore & #启动远程模式,否则你只能在本地登录
|
1
2
3
4
5
6
7
|
[root@HMaster0 ~]
# jps
2615 DFSZKFailoverController
30027 ResourceManager
29656 NameNode
25451 Jps
10270 HMaster
14975 RunJar
#会启动一个RunJar进程
|
1
2
3
4
5
6
|
[root@HMaster0 ~]
# hive
Logging initialized usingconfiguration
in
file
:
/opt/apache-hive-1
.2.0-bin
/conf/hive-log4j
.properties
hive> show databases;
OK
default
Time taken: 0.986 seconds,Fetched: 1 row(s)
|
1
2
|
# tar zxvf apache-hive-1.2.0-bin.tar.gz
# mv apache-hive-1.2.0-bin /opt
|
1
2
3
4
5
6
7
8
|
# vi hive-site.xml
<configuration>
<!--通过thrift方式连接hive-->
<property>
<name>hive.metastore.uris<
/name
>
<value>thrift:
//192
.168.18.215:9083<
/value
>
<
/property
>
<
/configuration
>
|
1
|
# /opt/apache-hive-1.2.0-bin/bin/hive
|
1
|
hive> create database
test
;
|
1
|
hive> create table tb1(
id
int,name string)row
format
delimited fields terminated by
'\t'
|
1
|
hive> create table tb3 like tb1;
|
1
2
3
4
5
|
hive> describe tb3;
OK
id
int
name string
Time taken: 0.091 seconds, Fetched: 2 row(s)
|
1
2
3
4
|
# cat kv.txt
1 zhangsan
2 lisi
3 wangwu
|
1
|
hive> load data
local
inpath
'/root/kv.txt'
overwrite into table tb1;
|
1
2
3
4
5
|
# hadoop fs -cat /kv.txt #查看hdfs中要导入的数据
1 zhangsan
2 lisi
3 wangwu
hive> load data inpath
'/kv.txt'
overwrite into table tb1;
|
1
2
3
4
5
6
|
hive>
select
* from tb1;
OK
1 zhangsan
2 lisi
3 wangwu
Time taken: 0.209 seconds,Fetched: 3 row(s)
|
1
|
hive> create table tb2(idint,name string) partitioned by (dt string) row
format
delimited fieldsterminated by
'\t'
;
|
1
2
|
hive> load data
local
inpath
'/root/kv.txt'
into table tb2 partition (dt=
'2015-06-26'
);
hive> load data
local
inpath
'/root/kv.txt'
into table tb2 partition (dt=
'2015-06-27'
);
|
1
2
3
4
5
6
7
8
9
|
hive>
select
* from tb2;
OK
1 zhangsan 2015-06-26
2 lisi 2015-06-26
3 wangwu 2015-06-26
1 zhangsan 2015-06-27
2 lisi 2015-06-27
3 wangwu 2015-06-27
Time taken: 0.223 seconds,Fetched: 6 row(s)
|
1
2
3
4
5
|
# hadoop fs -ls -R /user/hive/warehouse/test.db/tb2
drwxr-xr-x - root supergroup 0 2015-06-26 04:12
/user/hive/warehouse/test
.db
/tb2/dt
=2015-06-26
-rwxr-xr-x 3 root supergroup 27 2015-06-26 04:12
/user/hive/warehouse/test
.db
/tb2/dt
=2015-06-26
/kv
.txt
drwxr-xr-x - root supergroup 0 2015-06-26 04:15
/user/hive/warehouse/test
.db
/tb2/dt
=2015-06-27
-rwxr-xr-x 3 root supergroup 27 2015-06-26 04:15
/user/hive/warehouse/test
.db
/tb2/dt
=2015-06-27
/kv
.txt
|
1
|
hive> create table tb3(idint,name string) partitioned by (dt string,location string) row formatdelimited fields terminated by
'\t'
;
|
1
2
|
hive> load data
local
inpath
'/root/kv.txt'
into table tb3 partition (dt=
'2015-06- 26'
,location=
'beijing'
);
hive> load data
local
inpath
'/root/kv.txt'
into table tb3 partition (dt=
'2015-06-27'
,location=
'shanghai'
);
|
1
2
3
4
5
6
7
8
9
|
hive>
select
* from tb3;
OK
1 zhangsan 2015-06-26 beijing
2 lisi 2015-06-26 beijing
3 wangwu 2015-06-26 beijing
1 zhangsan 2015-06-26 shanghai
2 lisi 2015-06-26 shanghai
3 wangwu 2015-06-26 shanghai
Time taken: 0.208 seconds,Fetched: 6 row(s)
|
1
|
<span style=
"color:rgb(0,0,0);"
>
# hadoop fs -ls -R /user/hive/warehouse/test.db/tb3<br> drwxr-xr-x - root supergroup 0 2015-06-26 04:35/user/hive/warehouse/test.db/tb3/dt=2015-06-26<br> drwxr-xr-x - root supergroup 0 2015-06-26 04:35 /user/hive/warehouse/test.db/tb3/dt=2015-06-26/location=beijing<br> -rwxr-xr-x 3 root supergroup 27 2015-06-26 04:35/user/hive/warehouse/test.db/tb3/dt=2015-06-26/location=beijing/kv.txt<br> drwxr-xr-x - root supergroup 0 2015-06-26 04:45 /user/hive/warehouse/test.db/tb3/dt=2015-06-27<br> drwxr-xr-x - root supergroup 0 2015-06-26 04:45/user/hive/warehouse/test.db/tb3/dt=2015-06-27/location=shanghai<br> -rwxr-xr-x 3 root supergroup 27 2015-06-26 04:45/user/hive/warehouse/test.db/tb3/dt=2015-06-27/location=shanghai/kv.txt<br></span>
|
1
|
hive> show partitions tb2;
|
1
|
hive>
select
name from tb3 where dt=
'2015-06-27'
;
|
1
|
hive> alter table tb3 partition (dt=
'2015-06-27'
,location=
'shanghai'
) rename to partition(dt=
'20150627'
,location=
'shanghai'
);
|
1
|
hive> alter table tb3 droppartition (dt=
'2015-06-26'
,location=
'shanghai'
);
|
1
|
hive> show tables
'tb*'
;
|
1
|
hive> alter table tb1 addcolumns (commnet string);
|
1
|
hive> alter table tb1 rename to new_tb1;
|
1
|
hive> drop table new_tb1;
|
1
2
|
# cp /opt/apache-hive-1.2.0-bin/lib/jline-2.12.jar /opt/hadoop-2.6.0/share/hadoop/yarn/lib/
# rm /opt/hadoop-2.6.0/share/hadoop/yarn/lib/jline-0.9.94.jar
|
1
|
# cp mysql-connector-java-5.1.10-bin.jar /opt/apache-hive-1.2.0-bin/lib
|