Hive命令总结...

Hive启动

方式一:启动shell交互

  • Hive交互shell
bin/hive

方式二:Hive服务,与传统数据库JDBC类似

  • 前台启动
bin/hiveserver2
  • 后台启动
nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/var/log/hiveserver.err &
  • 远程连接
./beeline -u jdbc:hive2://IP地址:10000 -n 用户名

hive基本操作

创建数据库

#test是数据库名字, 可以随意
create database if not exists test;
#在创建数据库时指定数据库存放路径,注意:location后接的路径必须是绝对路径!!!:
create database if not exists testdb1 location '/home/xxx/hive/warehouse1';
#在创建数据库时为数据库添加注释
create database if not exists testdb2 comment 'test db2';

显示所有数据库

show databases;
#使用正则表达式筛选并显示数据库:
show databases like "h*";

切换数据库

use 数据库名;
#查看当前数据库
select current_database();

显示某个数据库详细信息

describe database testdb;

表操作

准备数据(上传到hdfs,路径/hdfs/ag_admin_v1748162c9dada4763a5f5ff3bf0c55a1f/weblog1ec483e8649542b895b15f844124c121__edb93d9d_cbdd_445f_8de5_35b2feb628ac.gz)

3537	[{"accounts":"yuanzhi","password":"123456"}]	2019-09-16 11:01:32
3538	[{"id":null,"organizeId":null,"sysDutiesname":null,"sysDutiescode":null,"sysDutiesstatus":null,"sysRemark":null},{"current":1,"size":100,"asc":null,"desc":null}]	2019-09-16 11:01:40
3539	[{"isDeleted":null,"id":null,"organizeId":null,"sysDeptname":null,"sysDeptphone":null,"sysDeptfax":null,"sysRemark":null,"sysExtension":null,"sysDeptcode":null,"sysDeptmail":null},{"current":1,"size":100,"asc":null,"desc":null}]	2019-09-16 11:01:40
3540	[{"id":null,"organizeId":null,"sysRolename":null,"sysRolestatus":null,"sysMenulist":null,"sysDatapermissions":null,"sysRemark":null,"createUser":null,"createTime":null,"updateUser":null,"updateTime":null},{"current":1,"size":100,"asc":null,"desc":null}]	2019-09-16 11:01:40

#创建内部表
create table biao_zhun_biao(a string) row format delimited fields terminated by '\t';
#创建外部表
create external table if not exists weblog_textfile(id string,question string, time string) row format delimited fields terminated by '\t' stored as textfile;
#导入数据
load data inpath '/hdfs/ag_admin_v1748162c9dada4763a5f5ff3bf0c55a1f/weblog1ec483e8649542b895b15f844124c121__edb93d9d_cbdd_445f_8de5_35b2feb628ac.gz' overwrite into table weblog_textfile;

#查询导入数据之后的表,这里建表时分隔符写错了
select * from weblog_textfile limit 3;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+-----------------------+--+
|                                                                                                                       weblog_textfile.id                                                                                                                       | weblog_textfile.question  | weblog_textfile.time  |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+-----------------------+--+
| 3537  [{"accounts":"yuanzhi","password":"123456"}]    2019-09-16 11:01:32                                                                                                                                                                                          | NULL                      | NULL                  |
| 3538  [{"id":null,"organizeId":null,"sysDutiesname":null,"sysDutiescode":null,"sysDutiesstatus":null,"sysRemark":null},{"current":1,"size":100,"asc":null,"desc":null}]       2019-09-16 11:01:40                                                                     | NULL                      | NULL                  |
| 3539  [{"isDeleted":null,"id":null,"organizeId":null,"sysDeptname":null,"sysDeptphone":null,"sysDeptfax":null,"sysRemark":null,"sysExtension":null,"sysDeptcode":null,"sysDeptmail":null},{"current":1,"size":100,"asc":null,"desc":null}]2019-09-16 11:01:40  | NULL                      | NULL                  |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+-----------------------+--+
3 rows selected (0.089 seconds)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值