Installation and use of Hive in data Warehouse
Hive is a Hadoop-based data warehouse tool that can be used for data collation, special query and analysis of data sets stored in Hadoop files.
1. Download the installation file
Http://mirror.bit.edu.cn/apache/hive/
# download Hive installation files
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
# decompression
Hadoop@dblab:/usr/local$ sudo tar-zxvf apache-hive-1.2.2-bin.tar.gz-C. /
# change the folder name to hive
Hadoop@dblab:/usr/local$ sudo mv apache-hive-1.2.2-bin hive
# modify file permissions
Hadoop@dblab:/usr/local$ sudo chown-R hadoop:hadoop hive
two。 Configure environment variables
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. Start 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 >
Basic operation of 4.Hive
1) create a database 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) create tables
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
# create a partition table usr1 in the hive database and get it by copying usr
Hive > create table if not exists user1 like usr
OK
Hive > show tables
OK
User1
Usr
3) create a view
Hive > create view little_usr as select id,age from usr
4) modify the database
Hive > alter database hive set dbproperties ('edit=by'='lily')
5) View the database
Hive > show databases
Default
Hive
6) View tables and views
Hive > use hive
Hive > show tables
Little_usr
User1
Usr
7) description database
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) tracing tables and views
Hive > describe hive.usr
Id bigint
Name string
Age int
Hive > describe hive.little_usr
Id bigint
Age int
9) modify the table
# modify the table name
Hive > alter table usr rename to users
Hive > alter table usr add columns (sex boolean)
10) delete the view
Hive > drop view if exists little_usr
11) delete the table
Hive > drop table if exists usr
12) Delete the database
Hive > drop database hive
13) exit Hive
Hive > quit
Hive > exit