连接hive beeline
beeline -u "jdbc:hive2://localhost:10000/default"
查看数据库下的表
show tables;
查询数据库
show databases;
新建一个数据库
create database myhive2
再次查询
show databases;
使用此数据库
use myhive2;
执行如下命令
CREATE TABLE IF NOT EXISTS employee_external (
name string,
work_place ARRAY,
sex_age STRUCT,
skills_score MAP,
depart_title MAP>
)
COMMENT 'This is an external table'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE
之后我们查看一下表
select * from employee_internal;
下面我们导入数据查看具体变化
文件地址
https://gitee.com/shuijin666/hive_basic_introductory_data.git
下载 employee.txt
然后put到
此路径下刷新之后见上图
select * from employee_internal;
之后效果图如下
结束,
外部表创建方式:
CREATE EXTERNAL TABLE IF NOT EXISTS employee_external (
name string,
work_place ARRAY,
sex_age STRUCT,
skills_score MAP,
depart_title MAP>
)
COMMENT 'This is an external table'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE
LOCATION '/user/dayongd/employee';
注意第一行的external外部表标识,还有最下面的location指明你要放置的路径
所以put的时候放到外部表路径下即可
内部表和外部表的区别除了上述还有在删除的时候,内部表的数据会都删除,外部表你的location下的不会被删除,当然你可以用hdfs dfs -cat去查看里面的内容,除此之外还有临时表