准备数据
/home/hadoop/
helloworld.txt
1 hello
2 world
3 welcome
创建数据库
hive> create database test_db;
hive> show databases;
创建一张表
hive> use test_db;
hive> create table helloworld(id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
hive> show tables;
查询表
hive> select * from helloworld;
OK # 没有数据
Time taken: 0.34 seconds
加载数据
hive> load data local inpath '/home/hadoop/helloworld.txt' overwrite into table helloworld;
再次查询表
hive> select * from helloworld;
OK
1 hello
2 world
3 welcome
Time taken: 0.068 seconds, Fetched: 3 row(s)
统计表
会生成MapReduce作业
hive> select count(1) from helloworld;
...
OK
3
Time taken: 2.731 seconds, Fetched: 1 row(s)