hive的帮助命令:
[hadoop@master tmp]$ hive -helpusage: hive -d,--defineVariable substitution to apply to Hive commands. e.g. -d A=B or --define A=B --database Specify the database to use -e SQL from command line -f SQL from files -H,--help Print help information --hiveconf Use value for given property --hivevar Variable substitution to apply to Hive commands. e.g. --hivevar A=B -i Initialization SQL file -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
*hive -e --不进入交互式,直接执行
[hadoop@master tmp]$ hive -e "select * from db_hive.u2;" Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true OK u2.id u2.name u2.age u2.month u2.day 1 xm1 16 9 14 2 xm2 18 9 14 3 xm3 22 9 14 4 xh4 20 9 14 5 xh5 22 9 14 6 xh6 23 9 14 7 xh7 25 9 14 8 xh8 28 9 14 9 xh9 32 9 14 Time taken: 5.155 seconds, Fetched: 9 row(s
[hadoop@master tmp]$ more hivef.sqlselect * from db_hive.u2;
hive -f hivef.sql
[hadoop@master tmp]$ hive -f hivef.sqlLogging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: trueOKu2.id u2.name u2.age u2.month u2.day1 xm1 16 9 142 xm2 18 9 143 xm3 22 9 144 xh4 20 9 145 xh5 22 9 146 xh6 23 9 147 xh7 25 9 148 xh8 28 9 149 xh9 32 9 14Time taken: 5.398 seconds, Fetched: 9 row(s)
还可以重定向到文件中:
[hadoop@master tmp]$ hive -f hivef.sql>hive_result.txtLogging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: trueOKTime taken: 5.224 seconds, Fetched: 9 row(s)
查看文件:
[hadoop@master tmp]$ ls -rlt-rw-rw-r--. 1 hadoop hadoop 26 Apr 2 23:38 hivef.sql-rw-rw-r--. 1 hadoop hadoop 163 Apr 2 23:49 hive_result.txt[hadoop@master tmp]$ more hive_result.txt u2.id u2.name u2.age u2.month u2.day1 xm1 16 9 142 xm2 18 9 143 xm3 22 9 144 xh4 20 9 145 xh5 22 9 146 xh6 23 9 147 xh7 25 9 148 xh8 28 9 149 xh9 32 9 14