HIVE在命令行里执行HQL

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


  -i             Initialization Sql from file (executed automatically and silently before any other commands)
  -e 'quoted query string'  Sql from command line
  -f             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已经改成其他关系型数据库的话这个问题就不存在了。


你可能感兴趣的:(HIVE在命令行里执行HQL)