hive使用方式

第一种交互方式:Hive交互shell
cd /export/servers/hive-1.1.0-cdh5.14.0
bin/hive

查看所有的数据库
hive (default)> show databases;

创建一个数据库
hive (default)> create database myhive;
使用该数据库并创建数据库表
hive (default)> use myhive;
hive (myhive)> create table test(id int,name string);

以上命令操作完成之后,一定要确认mysql里面出来一个数据库hive

第二种交互方式:Hive JDBC服务
启动hiveserver2服务

    前台启动

cd  /export/servers/hive-1.1.0-cdh5.14.0
bin/hive --service hiveserver2

在这里插入图片描述

后台启动


cd  /export/servers/hive-1.1.0-cdh5.14.0
nohup bin/hive --service hiveserver2  &

推荐:
beeline连接hiveserver2
bin/beeline
beeline> !connect jdbc:hive2://node03.hadoop.com:10000

在这里插入图片描述
注意:如果使用beeline方式连接hiveserver2,一定要保证hive在mysql当中的元数据库已经创建成功,不然就会拒绝连接

第三种交互方式:Hive命令
使用 –e 参数来直接执行hql的语句
bin/hive -e “use myhive;select * from test;”

使用 –f 参数通过指定文本文件来执行hql的语句
vim hive.sql
use myhive;select * from test;

bin/hive -f hive.sql
更多参数参考以下

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43924642/article/details/89540665