溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

數據倉庫Hive的安裝和使用

發布時間:2020-07-23 13:22:15 來源:網絡 閱讀:524 作者:sky9890 欄目:大數據

? ? ?Hive是一個基于Hadoop的數據倉庫工具,可以用于對存儲在Hadoop 文件中的數據集進行數據整理、特殊查詢和分析處理。

1.下載安裝文件

http://mirror.bit.edu.cn/apache/hive/

#下載Hive安裝文件

hadoop@dblab:/usr/local$ sudo wget http://mirror.bit.edu.cn/apache/hive/hive-1.2.2/apache-hive-1.2.2-bin.tar.gz?

#解壓

hadoop@dblab:/usr/local$ sudo tar -zxvf apache-hive-1.2.2-bin.tar.gz -C ./

#將文件夾名改為hive

hadoop@dblab:/usr/local$ sudo mv apache-hive-1.2.2-bin? hive

#修改文件權限?

hadoop@dblab:/usr/local$ sudo chown -R hadoop:hadoop hive

2.配置環境變量

hadoop@dblab:/usr/local$ vim ~/.bashrc

export HIVE_HOME=/usr/local/hive

export PATH=$PATH:$HIVE_HOME/bin

hadoop@dblab:/usr/local$ source ~/.bashrc

3.啟動Hive

hadoop@dblab:/usr/local/hive/conf$ cd /usr/local/hadoop/

hadoop@dblab:/usr/local/hadoop$ ./sbin/start-dfs.sh

hadoop@dblab:/usr/local/hadoop$ cd /usr/local/hive/

hadoop@dblab:/usr/local/hive$ ./bin/hive

hive>?

4.Hive基本操作

1)創建數據庫Hive

hive> create database hive;

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Database hive already exists

?hive> create database if not exists hive;

OK

hive> use hive;

OK

2)創建表

hive> create table if not exists usr(id bigint,name string,age int);

OK

hive> create table if not exists hive.usr(id bigint,name string,age int)

? ? > location '/usr/local/hive/warehouse/hive/usr';

OK

Time taken: 0.467 seconds

hive> create external table if not exists hive.usr(id bigint,name string,age int)

? ? > row format delimited fields terminated by ','

? ? > location '/usr/local/data';

OK

Time taken: 0.079 seconds

#在hive數據庫中創建分區表usr1,通過復制usr得到

hive> create table if not exists user1 like usr;

OK

hive> show tables;

OK

user1

usr

3)創建視圖

hive> create view little_usr as select id,age from usr;

4)修改數據庫

hive> alter database hive set dbproperties('edit=by'='lily');

5)查看數據庫

hive> show databases;

default

hive

6)查看表和視圖

hive> use hive;

hive> show tables;

little_usr

user1

usr

7)描述數據庫

hive> describe database hive;

hive? ? ? ? ? ? hdfs://localhost:9000/user/hive/warehouse/hive.db? ? ? ?hadoop? USER

hive> describe database extended hive;

hive? ? ? ? ? ? hdfs://localhost:9000/user/hive/warehouse/hive.db? ? ? ?hadoop? USER? ? {edit=by=lily}

8)描術表和視圖

hive> describe hive.usr;

id? ? ? ? ? ? ? bigint? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

name? ? ? ? ? ? string? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

age? ? ? ? ? ? int? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

hive> describe hive.little_usr;

id? ? ? ? ? ? bigint? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

age? ? ? ? ? ?int? ??

9)修改表

#修改表名

hive> alter table usr rename to users;

hive> alter table usr add columns(sex boolean);

10)刪除視圖

hive> drop view if exists little_usr;

11)刪除表

hive> drop table if exists usr;

12)刪除數據庫

hive> drop database hive;

13)退出Hive

hive> quit;

hive> exit;

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女