Hive:02-hive安裝與基本使用

--後面會陸續方便大數據相關筆記,

--01.linux

--02.hadoop  

--03.zookeeper

--04.hive

1.上傳文件
apache-hive-1.2.1-bin.tar.gz

2.解壓
tar -zvxf apache-hive-1.2.1-bin.tar.gz
mv apache-hive-1.2.1-bin.tar.gz hive-1.2.1

3.修改配置文件
新增一個hive-site.xml文件
vim hive-site.xml

<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://bigdata04:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>

<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>

<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>

<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>


4.增加一個mysql jdbc 連接jar(目錄:/root/training/hive-1.2.1/lib)


5.啓動hadoop
start-dfs.sh (http://192.168.111.101:50070/)
start-yarn.sh (http://192.168.111.101:8088/)

6.配置hadoop home 和 hive home
vim /etc/profile
source /etc/profile

7.啓動hive 
a) cd /root/training/hive-1.2.1
b) bin/hive

8.查看默認庫
show databases;

9.創建庫
create database bigdata03;

10.創建表
create table t_bigdata03(id int,name string,age int,sex string);

11.查詢
select * from t_bigdata03;

12.hdfs目錄
/user/hive/warehouse

13.在bigdata02創建測試數據
 mkdir hivetest
 vim stu.info   (默認分割:\001 ,^A= CTRL+V+A)  
1^Asjy^A31^Afemale
2^Aspf^A30^Amale
3^Ayt^A29^Afemale
4^Awxy^A28^Afemale

14.上傳文件
hadoop fs -put stu.info /user/hive/warehouse/t_bigdata03/
(hadoop fs -rm stu.info /user/hive/warehouse/t_bigdata03/stu.info)

select * from t_bigdata03;

15.mysql查看錶
庫存放DBS
表存放:TBLS
字段:COLUMNS_V2


16.統計查詢
select count(1) from t_bigdata03;

17.yarn運行
修改配置文件

18. 查詢年齡範圍
select * from t_bigdata03 where age > 30;

19.分組查詢
select sex,count(1) as number from t_bigdata03 group by sex;
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章