Hive installation and basic use

Source: Internet
Author: User
Tags dname

1. Install JDK and set Environment Variables

2. Upload the installation package

3. Decompress

4. Set Environment Variables
# Vi ~ /. Bash_profile or VI/etc/profile
5. Go to hive Shell
# Hive Shell
Or
# Hive

6. Common Operations

View database list
Hive> show databses;

View table list
Hive> show tables;
View table structure
Hive> DESC table_name;
Create a database. The location is the path in HDFS. directories that do not exist are automatically created.
Hive> Create external table test (ID int, name string)
> Comment 'this is a test table'
> Row format delimited fields terminated by '\ t'
> Stored as textfile
> Location '/data/text/test.txt ';
Hive> DESC test1;
Hive> select * From test1;

We recommend that the table name and data file name be consistent.
/*************************************** **************************************** ******
Create external table Stu (ID int, name string)
Comment 'this is a test table'
Row format delimited fields terminated by '\ t'
Stored as textfile
Location '/data/test/stu.txt ';
**************************************** **************************************** *****/

After creating a database, you can quickly upload data. Data in/home/hadoop/filelx/test.txt is separated by tabs, and the number of columns is the same as that in the created table.
# Hadoop DFS-Put/home/hadoop/filelx/test.txt/data/test/test.txt

Append Loading
Hive> load data local inpath '/home/hadoop/filelx/test.txt' into Table test1;
Overwrite and Load
Hive> load data local inpath '/home/hadoop/filelx/test.txt' overwrite into Table test1;


Create a partition table:
Hive> Create Table T1 (ID int, name string) partitioned by (hiredate string) Row format delimited fields terminated ',';
Hive> Create Table test1 (ID int, name string) partitioned by (dname string) Row format delimited fields terminated by ', 'stored as textfile;
Hive> load data local inpath'/home/hadoop/filelx/1.txt 'Overwrite into Table test1 partition (dname = 'manager ');
Hive> load data local inpath '/home/hadoop/filelx/2.txt' overwrite into Table test1 partition (dname = 'developer ');
View partitions
Hive> show partition test1;
Hive> select * From test1 where dname = 'dev ';
Hive> select * From test1 where dname = 'manager ';

Hive> insert overwrite table T1 partition (hiredate = '2013') Select ID, name from test1 where dname = 'develop
Hive> show partition T1;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.