$王大少

导航

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);

 

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

  就是启动一个服务

    前台启动:

        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 2>&1 &

  然后再通过beeline连接hiveserver2:

    bin/beeline

    beeline> !connect jdbc:hive2://node03.hadoop.com:10000

第三种交互方式: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

 

 

 

 

 

posted on 2020-03-31 16:05  $王大少  阅读(522)  评论(0编辑  收藏  举报