启动服务器:
bin/hive --service metastore
nohup bin/hive --service metastore &
nohup bin/hiveserver2 &
启动客户端:bin/hive
数据库的CRUD
DDL--单用户模式
创建一个数据库:create database mydata;
创建一张表:create table psn_1(id int,name string);
插入一条记录:insert into psn_1(id,name)values(1,'aa');
# 在MySQL数据库中查看
创建的数据库:hive-demo --表--dbs
创建的表:hive-demo --表--tbls
列:hive-demo --表--columns_v2
# 记录放到了HDFS上
node7-1:9870/explorer.html#/dada/hive/data
DDL--多用户模式
创建数据库:create database my_1;
查看数据库:show databases;
我在哪个数据库:select current_database() ;
切换数据库:use mydata ;
修改数据库属性:alter database my_1 set location 'hdfs://jh/mr/my_1';
删除数据库:drop database test_my;
表的CRUD
创建简单的表
create table psn_1
(
id int comment '这是id',
name string comment '这是名字',
age tinyint,
score double,
createTime timestamp
)
comment '这是表的注释';
查看表:show tables;
查看单张表:desc psn_1 ;
描述库:desc database mydata ;
描述表:describe formatted psn_1 ;
修改表名:alter table psn_1 rename to psn_11 ;
修改表的列名:alter table psn_11 change age age_1 int ;
增加新列和替换列:
alter table psn_11 add columns
(
sex smallint,
updateTime timestamp
);
删除表:drop table psn_11 ;
记录的CRUD
记录只有添加
insert into psn_1 values (1,'aa',20,90.2,'2020-08-10 11:11:11');
insert into psn_1 values (2,'bb',