Hive启动
方式一:启动shell交互
bin/hive
方式二:Hive服务,与传统数据库JDBC类似
bin/hiveserver2
nohup bin/hiveserver2 1> /var/log/hiveserver.log 2> /var/log/hiveserver.err &
./beeline -u jdbc:hive2://IP地址:10000 -n 用户名
hive基本操作
创建数据库
create database if not exists test ;
create database if not exists testdb1 location '/home/xxx/hive/warehouse1' ;
create database if not exists testdb2 comment 'test db2' ;
显示所有数据库
show databases;
show databases like "h*" ;
切换数据库
use 数据库名;
select current_database( ) ;
显示某个数据库详细信息
describe database testdb;
表操作
准备数据(上传到hdfs,路径/hdfs/ag_admin_v1748162c9dada4763a5f5ff3bf0c55a1f/weblog1ec483e8649542b895b15f844124c121__edb93d9d_cbdd_445f_8de5_35b2feb628ac.gz)
3537 [{"accounts":"yuanzhi","password":"123456"}] 2019-09-16 11:01:32
3538 [{"id":null,"organizeId":null,"sysDutiesname":null,"sysDutiescode":null,"sysDutiesstatus":null,"sysRemark":null},{"current":1,"size":100,"asc":null,"desc":null}] 2019-09-16 11:01:40
3539 [{"isDeleted":null,"id":null,"organizeId":null,"sysDeptname":null,"sysDeptphone":null,"sysDeptfax":null,"sysRemark":null,"sysExtension":null,"sysDeptcode":null,"sysDeptmail":null},{"current":1,"size":100,"asc":null,"desc":null}] 2019-09-16 11:01:40
3540 [{"id":null,"organizeId":null,"sysRolename":null,"sysRolestatus":null,"sysMenulist":null,"sysDatapermissions":null,"sysRemark":null,"createUser":null,"createTime":null,"updateUser":null,"updateTime":null},{"current":1,"size":100,"asc":null,"desc":null}] 2019-09-16 11:01:40
create table biao_zhun_biao( a string) row format delimited fields terminated by '\t' ;
create external table if not exists weblog_textfile( id string, question string, time string) row format delimited fields terminated by '\t' stored as textfile;
load data inpath '/hdfs/ag_admin_v1748162c9dada4763a5f5ff3bf0c55a1f/weblog1ec483e8649542b895b15f844124c121__edb93d9d_cbdd_445f_8de5_35b2feb628ac.gz' overwrite into table weblog_textfile;
select * from weblog_textfile limit 3 ;
+
| weblog_textfile. id | weblog_textfile. question | weblog_textfile. time |
+
| 3537 [ {"accounts" :"yuanzhi" , "password" :"123456" }] 2019 - 09 - 16 11 :01 :32 | NULL | NULL |
| 3538 [ {"id" :null , "organizeId" :null , "sysDutiesname" :null , "sysDutiescode" :null , "sysDutiesstatus" :null , "sysRemark" :null }, {"current" :1 , "size" :100 , "asc" :null , "desc" :null }] 2019 - 09 - 16 11 :01 :40 | NULL | NULL |
| 3539 [ {"isDeleted" :null , "id" :null , "organizeId" :null , "sysDeptname" :null , "sysDeptphone" :null , "sysDeptfax" :null , "sysRemark" :null , "sysExtension" :null , "sysDeptcode" :null , "sysDeptmail" :null }, {"current" :1 , "size" :100 , "asc" :null , "desc" :null }] 2019 - 09 - 16 11 :01 :40 | NULL | NULL |
+
3 rows selected ( 0.089 seconds)