hive 基本操作
命令:hive shell || hive --service cli
进入shell后
1. 设置显示当前database和显示列字段
set hive.cli.print.current.db=true //显示当前db
set hive.cli.print.headers=true //显示列
2. 相关命令
show databases
show tables
use database_name
CREATE DATABASE database_name
//建表
create external table table_name(
id int,
name string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
//导出数据到本地
insert overwrite local directory '/root/data.dat'
select * from table_name;
//导出数据到另一个表
insert overwrite table to_table
select * from from_table
//导出数据到hdfs文件(比导出到本地少个local)
insert overwrite directory '/root/hdfs'
select * from from_table
//从本地文件导入数据到hive
LOAD DATA [LOCAL] INPATH '/data/userdata' [OVERWRITE] INTO TABLE user;
//OVERWRITE关键会全表覆盖,如果只是想附加数据,将OVERWRITE去掉即可
//从hdfs导入数据到hive
LOAD DATA INPATH `/tmp/date.txt` OVERWRITE INTO TABLE page_view PARTITION(pt='2008-06-08')
//从某个表导入
NSERT OVERWRITE TABLE TMP_T1 SELECT * FROM TMP_T2;
命令:hive shell || hive --service cli
进入shell后
1. 设置显示当前database和显示列字段
set hive.cli.print.current.db=true //显示当前db
set hive.cli.print.headers=true //显示列
2. 相关命令
show databases
show tables
use database_name
CREATE DATABASE database_name
//建表
create external table table_name(
id int,
name string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
//导出数据到本地
insert overwrite local directory '/root/data.dat'
select * from table_name;
//导出数据到另一个表
insert overwrite table to_table
select * from from_table
//导出数据到hdfs文件(比导出到本地少个local)
insert overwrite directory '/root/hdfs'
select * from from_table
//从本地文件导入数据到hive
LOAD DATA [LOCAL] INPATH '/data/userdata' [OVERWRITE] INTO TABLE user;
//OVERWRITE关键会全表覆盖,如果只是想附加数据,将OVERWRITE去掉即可
//从hdfs导入数据到hive
LOAD DATA INPATH `/tmp/date.txt` OVERWRITE INTO TABLE page_view PARTITION(pt='2008-06-08')
//从某个表导入
NSERT OVERWRITE TABLE TMP_T1 SELECT * FROM TMP_T2;