HIVE在命令行里执行HQL

Usage: hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e query-string>] [-S]


  -i <filename>             Initialization Sql from file (executed automatically and silently before any other commands)
  -e 'quoted query string'  Sql from command line
  -f <filename>             Sql from file
  -S                        Silent mode in interactive shell where only data is emitted
  -hiveconf x=y             Use this to set hive/hadoop configuration variables. 
  
   -e and -f cannot be specified together. In the absence of these options, interactive shell is started.  However, -i can be used with any other options.


   To see this usage help, run hive -h

在命令行里执行某HQL
$HIVE_HOME/bin/hive -e 'select a.col from tab1 a'

HIVE环境变量配置
$HIVE_HOME/bin/hive -e 'select a.col from tab1 a' -hiveconf hive.exec.scratchdir=/home/my/hive_scratch  -hiveconf mapred.reduce.tasks=32

将某表数据从HIVE中导出到文件
$HIVE_HOME/bin/hive -S -e 'select a.col from tab1 a' > a.txt

$HIVE_HOME/bin/hive -f /home/my/hive-script.sql

设置参数
$HIVE_HOME/bin/hive -f /home/hadoop/hive-0.7.0/myscript/hiveset.sql 

CREATE TABLE dw_cell_info(lac string,ci string,bs_id int,bs_name string,city_id string,city_name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE;
$HIVE_HOME/bin/hive -e 'CREATE TABLE dw_myloc_info(lac string,ci string,bs_id int,bs_name string,city_id string,city_name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE;'


$HIVE_HOME/bin/hive -e 'LOAD DATA LOCAL INPATH "/home/hadoop/dw_loc_info.txt" INTO TABLE dw_loc_info;'

LOAD DATA LOCAL INPATH '/home/hadoop/dw_loc_info.txt' INTO TABLE dw_loc_info;

在10.38.239.112上测试,得到结果

需要注意的是:

需要到/home/hadoop/hive-0.7.0/ 下做操作

hive-0.7.0]$ bin/hive -f /home/hadoop/hive-0.7.0/createtable.sql 

这样才会更新到hive-0.7.0目录下的metastore_db,否则直接

$HIVE_HOME/bin/hive -f /home/hadoop/hive-0.7.0/createtable.sql 的话,是更新到 /home/hadoop/ 目录下的metastore_db

当然,metadata已经改成其他关系型数据库的话这个问题就不存在了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值