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;