1、基于 Hadoop 3.x 集群搭建部署 Hive
2、搭建部署 Hive 3.1.2 分布式集群
[root@master ~]# /usr/bigdata/hadoop-3.3.0/sbin/stop-dfs.sh
[root@master ~]# /usr/bigdata/hadoop-3.3.0/sbin/start-yarn.sh
三、启动 Hive
1、在任一 Hive 客户端节点启动 hive
效果如下:
2、查看数据库列表
hive (default)> show databases;
OK
database_name
db_test
default
Time taken: 0.667 seconds, Fetched: 2 row(s)
3、选择数据库
hive (default)> use db_test;
OK
Time taken: 0.037 seconds
4、创建表 students、hive_user
hive (db_test)> create table students(id int,name string,age int);
OK
Time taken: 0.534 seconds
hive (db_test)> create table hive_user(id int,username string,passwd string);
OK
Time taken: 0.069 seconds
5、查看数据库列表
hive (db_test)> show tables;
OK
tab_name
students
hive_user
Time taken: 0.052 seconds, Fetched: 1 row(s)
6、正则查看数据库列表
hive (db_test)> show tables'.*s';
OK
tab_name
students
Time taken: 0.035 seconds, Fetched: 1 row(s)
7、查看表结构
hive (db_test)> describe students;
OK
col_name data_type comment
id int
name string
age int
Time taken: 0.058 seconds, Fetched: 3 row(s)
hive (db_test)> describe hive_user;
OK
col_name data_type comment
id int
username string
passwd string
Time taken: 0.065 seconds, Fetched: 3 row(s)
8、重命名指定表
hive (db_test)> alter table hive_user rename to hive_user_test;
OK
Time taken: 0.19 seconds
hive (db_test)> show tables;
OK
tab_name
hive_user_test
students
Time taken: 0.04 seconds, Fetched: 2 row(s)
9、查看制定表重命名后的表结构
hive (db_test)> describe hive_user_test;
OK
col_name data_type comment
id int
username string
passwd string
Time taken: 0.06 seconds, Fetched: 3 row(s)
10、对指定标增加列
hive (db_test)> alter table hive_user_test add columns(phone string);
OK
Time taken: 0.11 seconds
hive (db_test)> describe hive_user_test;
OK
col_name data_type comment
id int
username string
passwd string
phone string
Time taken: 0.06 seconds, Fetched: 4 row(s)
11、对指定表增加字段
hive (db_test)> alter table hive_user_test add columns(type string comment 'userType');
OK
Time taken: 0.107 seconds
hive (db_test)> describe hive_user_test;
OK
col_name data_type comment
id int
username string
passwd string
phone string
type string userType
Time taken: 0.058 seconds, Fetched: 5 row(s)
12、对指定表字段增加备注
hive (db_test)> alter table hive_user_test replace columns(id int,username string,passwd string,usertype string comment 'userType');
OK
Time taken: 0.101 seconds
hive (db_test)> describe hive_user_test;
OK
col_name data_type comment
id int
username string
passwd string
usertype string userType
Time taken: 0.053 seconds, Fetched: 4 row(s)
13、删除指定表表
hive (db_test)> drop table students;
OK
Time taken: 0.244 seconds
hive (db_test)> show tables;
OK
tab_name
hive_user_test
Time taken: 0.032 seconds, Fetched: 1 row(s)
以上是对 Hive 表的部分基础操作,后期会继续扩展!