一 Hive的启动方式
1、CLI(命令行)方式
2、Web界面方式
3、远程服务启动方式
二 CLI(命令行方式)
1、直接输入hive
2、hive --service cli
3、静默模式
hive -S
[root@localhost ~]# hive
Logging initialized using configuration in jar:file:/root/apache-hive-0.13.0-bin/lib/hive-common-0.13.0.jar!/hive-log4j.properties
hive> quit;
[root@localhost ~]# hive --service cli
Logging initialized using configuration in jar:file:/root/apache-hive-0.13.0-bin/lib/hive-common-0.13.0.jar!/hive-log4j.properties
hive> exit;
三 常用的CLI命令
1、清屏:
Ctrl+L或者!clear
2、查看数据仓库中的表
show tables;
3、查看数据仓库中内置的函数
show functions;
4、查看表结构
desc 表名
5、查看HDFS上的文件
dfs -ls 目录
6、执行操作系统命令
!命令
7、执行HQL语句
select *** from ***
8、执行SQL的脚本
source SQL文件
9、操作系统下执行命令
hive -e 'show tables';
四 实战
hive> show tables;
OK
Time taken: 1.656 seconds
hive> show functions;
OK
> create table test1(tid int,tname string);
OK
Time taken: 1.944 seconds
hive>
> desc test1;
OK
tid int
tname string
Time taken: 0.664 seconds, Fetched: 2 row(s)
hive> dfs -ls /user;
Found 2 items
drwxr-xr-x - root supergroup 0 2017-08-23 20:55 /user/hive
drwxr-xr-x - root supergroup 0 2017-08-20 14:51 /user/root
hive> dfs -lsr /user;
drwxr-xr-x - root supergroup 0 2017-08-23 20:55 /user/hive
drwxr-xr-x - root supergroup 0 2017-08-23 20:55 /user/hive/warehouse
drwxr-xr-x - root supergroup 0 2017-08-23 20:55 /user/hive/warehouse/test1
> !pwd ;
hive> /root
> !ls ;
hive> 123
aa.av
a.av
abc
abcd
hive> select * from test1;
OK
Time taken: 3.628 seconds
hive> select tname from test1;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_201708231948_0001, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201708231948_0001
Kill Command = /opt/hadoop-1.2.1/libexec/../bin/hadoop job -kill job_201708231948_0001
Hadoop job information for Stage-1: number of mappers: 0; number of reducers: 0
2017-08-23 21:04:40,183 Stage-1 map = 0%, reduce = 0%
2017-08-23 21:04:58,012 Stage-1 map = 100%, reduce = 100%
Ended Job = job_201708231948_0001
MapReduce Jobs Launched:
Job 0: HDFS Read: 0 HDFS Write: 0 SUCCESS
Total MapReduce CPU Time Spent: 0 msec
OK
Time taken: 80.903 seconds
hive> source /root/my.sql;
OK
Time taken: 0.543 seconds
hive> source /root/my1.sql;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_201708231948_0002, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201708231948_0002
Kill Command = /opt/hadoop-1.2.1/libexec/../bin/hadoop job -kill job_201708231948_0002
Hadoop job information for Stage-1: number of mappers: 0; number of reducers: 0
2017-08-23 21:10:53,970 Stage-1 map = 0%, reduce = 0%
2017-08-23 21:11:14,799 Stage-1 map = 100%, reduce = 100%
Ended Job = job_201708231948_0002
MapReduce Jobs Launched:
Job 0: HDFS Read: 0 HDFS Write: 0 SUCCESS
Total MapReduce CPU Time Spent: 0 msec
OK
Time taken: 58.833 seconds
[root@localhost ~]# hive -S
hive> source /root/my1.sql;
hive>
[root@localhost ~]# hive -e 'show tables';
Logging initialized using configuration in jar:file:/root/apache-hive-0.13.0-bin/lib/hive-common-0.13.0.jar!/hive-log4j.properties
OK
test1
Time taken: 3.197 seconds, Fetched: 1 row(s)
[root@localhost conf]# hive -e 'select * from test1';
Logging initialized using configuration in jar:file:/root/apache-hive-0.13.0-bin/lib/hive-common-0.13.0.jar!/hive-log4j.properties
OK
Time taken: 6.289 seconds
[root@localhost conf]# hive -S -e 'select * from test1';
[root@localhost conf]#