hive基本命令

离开安全模式:
hadoop dfsadmin -safemode leave
(1)hive设置显示当前数据库:可在hive-site.xml中配置
set hive.cli.print.current.db=true;
(2)查询默认建表语句:
show create table 表名
(3)hive后台启动:(非必须)
nohup hive --service metastore &
(4)beeline后台启动:(必须)
nohup hiveserver2 &
(5)进入beeline:
beeline -u jdbc:hive2://localhost:10000

--退出
!q
(6)不进入beeline:
--执行hql语句
beeline -e "show databases;" -u  jdbc:hive2://localhost:10000

--直接执行hql文件(可写多条hql语句,一次性执行)
vi test.sql
test.sql里面的内容是:show databases;
beeline -u "jdbc:hive2://localhost:10000" -f test.sql
(7)查看jps的详细信息:
jps -lm
(8)查看数据库(myhivebook)的默认信息:
desc database myhivebook;
(9)更改数据库的用户名:
alter database myhivebook set owner user root;
(10)查看当前正在使用的库:
select current_database();
(11)查看表的定义格式:
desc formatted 表名;
(12)建库:(hive不区分大小写)
create database if not exists test;
use test;
(13)删库:
drop database if exists test cascade;
cascade关键字:删除库下的所有表
(14)内部表
(1)内部表的表数据都在其内部,hdfs上的/usr/hive/warehouse/库名/表名中
建内部表:指定文件格式和分割符
create table if not exists student(id int,name string)
row formated delimited fields terminated by ','
stored as textfile;

导入数据:
将文件导入到表:student的目录下

删除表student的同时会删除该目录下的数据文件
(15)外部表
(2)外部表的元数据存在mysql上的hive库中,表数据存放在hdfs上
建外部表:
create external table if not exists ext_student(id int,name string)
row format delimited fields terminated by ','
stored as textfile
location '/text'
(16)导入数据
load data [local] inpath '文件路径'
[overwrite] into table 表名

local:
有是代表虚拟机路径,没有就是hdfs路径

overwrite:
有是代表覆盖,没有就是追加
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值