1.查看数据库
show databases
2.创建数据库
create database test
create database test location ‘hdfs://test/test.db/’
3.删除数据库
drop database test //如果有表则不能删除
drop database test cascade //强制删除数据库
4.进入数据库
use test
5.查看表
show tables
6.创建表
create [external] table ylq (
id int,
name string comment ‘姓名’,
age int comment ‘年龄’
) partitioned (day string)
row format delimited
fields terminated by ‘|’
stored as textfile
location ‘hdfs://test/test.db./ylq’
关键字
external 创建外部表,删除表,不会删除表数据(表数据在hdfs上)
comment 注释
partitioned by 创建表分区
row format delimited 指定数据格式
fields terminated by ‘|’ //指定每行中字段分隔符为竖线
lines terminated by ‘\n’ //指定行分隔符
collection items terminated by ‘,’ //指定集合中元素之间的分隔符
map keys terminated by ‘:’ //指定数据中Map类型的Key与Value之间的分隔符
stored as hdfs上表存储数据的格式
textfile //文本
sequencefile // 二进制序列文件
rcfile //列式存储格式文件 Hive0.6以后开始支持
orc //列式存储格式文件,比RCFILE有更高的压缩比和读写效率,Hive0.11以后开始支持
parquet //列出存储格式文件,Hive0.13以后开始支持
location 指定文件在hdfs路径