Hive基本操作
(1)啟動hive
[atguigu@hadoop102 hive]$ bin/hive
(2)查看數據庫
hive> show databases;
(3)打開默認數據庫
hive> use default;
(4)顯示default數據庫中的表
hive> show tables;
(5)創建一張表
hive> create table student(id int, name string);
(6)顯示數據庫中有幾張表
hive> show tables;
(7)查看表的結構
hive> desc student;
(8)向表中插入數據
hive> insert into student values(1000,"ss");
(9)查詢表中數據
hive> select * from student;
(10)退出hive
hive> quit;
Hive實際操作
(1)啟動hive
[atguigu@hadoop102 hive]$ bin/hive
(2)顯示數據庫
hive> show databases;
(3)使用default數據庫
hive> use default;
(4)顯示default數據庫中的表
hive> show tables;
(5)刪除已創建的student表
hive> drop table student;
(6)創建student表, 並聲明文件分隔符’\t’
hive> create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED
BY '\t';
(7)加載/opt/module/datas/student.txt 文件到student數據庫表中。
hive> load data local inpath '/opt/module/datas/student.txt' into table student;
(8)Hive查詢結果
hive> select * from student;
OK
1001 zhangshan
1002 lishi
1003 zhaoliu
Time taken: 0.266 seconds, Fetched: 3 row(s)
