0.登录hive数据库,这里采用beeline
[secret ~]$ beeline
beeline> ! connect jdbc:hive2://10.1.1.1:10000
Enter username for jdbc:hive2://10.1.1.1:10000: secret
Enter password for jdbc:hive2://10.1.1.1:10000: *************
0: jdbc:hive2://10.1.1.1:10000> show databases;
0: jdbc:hive2://10.1.1.1:10000> use db_iot;
0: jdbc:hive2://10.1.1.1:10000> show tables;
0: jdbc:hive2://10.1.1.1:10000> describe iotdata;
1.创建数据库
有两种方式,可以在hive客户端或beeline连接hive创建,也可以在spark中创建,以hive shell 中创建为例,spark中只需hiveContext.sql(command)即可。
create database if not exists db_iot;
use db_iot;
//删除数据库
//drop database if exists db_iot;
2.创建数据表
同数据库一样,两种方式创建数据表,以hive shell 中创建为例
另:在spark中不创建直接saveAsTable写入表且指定分区列时,hive中可以查询表数据但查不到表的创建和修改信息,此时创建的表也不是分区表。
crea