目录
Hive常用交互命令
[hadoop@hadoop102 hive]$ bin/hive -help
usage: hive
-d,--define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable subsitution to apply to hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the console)
1)“-e”不进入hive的交互窗口执行sql语句
[hadoop@hadoop102 hive]$ bin/hive -e "select id from student;"
2)“-f”执行脚本中sql语句
(1)在/opt/module/hive/下创建datas目录并在datas目录下创建hivef.sql文件
[hadoop@hadoop102 datas]$ touch hivef.sql
(2)文件中写入正确的sql语句
select *from student;
(3)执行文件中的sql语句
[hadoop@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql
(4)执行文件中的sql语句并将结果写入文件中
[hadoop@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql > /opt/module/datas/hive_result.txt
Hive其他命令操作
1)退出hive窗口:
hive(default)>exit;
hive(default)>quit;
在新版的hive中没区别了,在以前的版本是有的:
exit:先隐性提交数据,再退出;
quit:不提交数据,退出;
2)在hive cli命令窗口中如何查看hdfs文件系统
hive(default)>dfs -ls /;
3)查看在hive中输入的所有历史命令
(1)进入到当前用户的根目录/root或/home/hadoop
(2)查看. hivehistory文件
[hadoop@hadoop102 ~]$ cat .hivehistory