Hive连接和使用

1、可以通过bin/hive进行命令行操作(CLl方式)

2、远程服务连接

先启动 metastore 服务:

nohup bin/hive --service metastore &

再启动 hiveserver2 服务:
nohup bin/hive --service hiveserver2 &

  输入远程连接命令:bin/beeline 

 输入到远程连接协议,连接到指定的hive服务的主机名和端口

 ! connect jdbc:hive2://bigdata02:10000

最后输入连接hive服务器的用户名和密码

 最后idea连接hive,类似数据库连接

3、查看数据库列表,创建数据库

 show databases;       查看数据库列表

 create database mydb1; 创建数据库

 create database mydb2 location 'user/hive/mydb2'; 指定数据库hdfs存储位置

 

创建表 create table t1(id int,name string);

 4、添加数据

 其中默认的数据库在hdfs中存储的位置 其中数据库表dbs中也可以查看相关数据库在hdfs存储的位置

5、查看表结构

1、 desc t1;  查看表结构信息

2、 show create table t1;查看表的创建信息

 在表columns_v2表中存储hive表的字段信息

 6、修改表名称,增加表字段

 alter table t2 rename to t2_bak;修改表名

  alter table t2_bak add columns(score string); 增加字段

7、加载数据

hive在创建表的时候,需要我们指定相应的行分隔符,默认是是\n,也就是换行符

  create table t3_new(
  id int comment 'ID',
  stu_name string comment 'name',
  stu_birthday date comment 'birthday',
  online boolean comment 'is online'
  )row format delimited
  fields terminated by '\t'
  lines terminated  by '\n'

 把数据导入表中

load data local inpath '/data/soft/hivedata/t2.data' into table t3_new;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值