HIVE的啟動及基本命令
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)