hive的启动命令

首先启动 zookeeper : bin/zkServer.sh restart

启动zookeeper以后查看是否启动成功 : bin/zkServer.sh status

在启 NameNode 和 DataNode 守护进程。sbin/start-all.sh

hive服务器启动命令:
启动 : nohup bin/hive --service metastore &

查看运行过程: tail -f nohup.out

客户端启动命令:bin/hive

如果连接.Beeline

启动服务器命令以后在启动: nohup bin/hiveserver2 &

启动客户端:bin/beeline

查看运行过程: tail -f nohup.out

连接客户端:
Jdbc的url;

!connect jdbc:hive2://node-4:10000 root 123456--没有跟上数据库,一定要切换数据库(use 数据库的名字);默认是default;
!connect jdbc:hive2://node-4:10000/mydata root 123456

 hive命令

查看数据库 : show databases ;

创建数据 : create database (要创建的数据库名字) ;

创建了一张表 :

create table psn_1(

id int,

name string

) ;

外部表:

1 CREATE EXTERNAL TABLE page_view(viewTime INT, userid BIGINT,
2      page_url STRING, referrer_url STRING,
3      ip STRING COMMENT 'IP Address of the User',
4      country STRING COMMENT 'country of origination')
5  COMMENT 'This is the staging page view table'
6  ROW FORMAT DELIMITED FIELDS TERMINATED BY '54'
7  STORED AS TEXTFILE
8  LOCATION '<hdfs_location>';

插入一条数据 : insert into psn_1 (id,name) values (1,‘aa’);

除数据库 : drop databases (要删除的数据库名字) ;

在mysql中可以,在hive中不可以 : show databases like '%da%'

数据库更改:数据一旦创建,不可更改,想要更改,先删除,再创建;(除了数据库名字以外的,都可以修改)

修改数据库属性 : alter database my_2 set location ‘hdfs://jh/mr/my_2’;

进入数据库 : Use 数据库的名字: use mydata ;

我在哪个数据库 : select current_database() ;

查看所有表 :show tables;

删除表格 : drop table (要删除的名字)

查看单张表 : desc (要查看的表名字) ;

查询记录 : select * from 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

);

向表里面导入数据 : load data inpath ‘/hw/multi_data.txt’ into table psn_10 partition (sex=‘boy’);

先导出 : export table psn_1 to ‘/hw/psn_1’ ;

可以在node-1上面查看导出的内容 : bin/hdfs dfs -cat /hw/psn_1/data/000000_0

再导入 : import table psn_1 from ‘/hw/psn_1’ 

原文地址:https://www.cnblogs.com/zhipeng-wang/p/14046124.html