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;