此篇博文博主为大家讲解的是Hive中常用的交互命令及其他的一些命令。
目录
- 一. Hive常用交互命令
-
- 1.1 “-e”不进入hive的交互窗口执行sql语句
- 1.2 “-f”执行sql脚本
- 二. Hive其他命令操作
-
- 2.1 退出hive窗口:
- 2.2 在hive client命令窗口中如何查看hdfs文件系统
- 2.3 在hive client命令窗口中如何查看本地文件系统
- 2.4 查看在hive中输入的所有历史命令
可 先 通 过 命 令 行 查 看 帮 助 \color{#FF0000}{可先通过命令行查看帮助} 可先通过命令行查看帮助
[bigdata@hadoop001 hive]$ bin/hive -help
# 查找学生表中的内容(如果不指定,自动默认访问)
[bigdata@hadoop001 hive]$ bin/hive -e "select * from student;"
# 指定访问
[bigdata@hadoop001 hive]$ bin/hive -e "select * from default.student;"
# 删除学生表
[bigdata@hadoop001 hive]$ bin/hive -e "drop table student;"
# 向学生表中插入信息
[bigdata@hadoop001 hive]$ bin/hive -e "insert into student values(1001,"zhangsan"),(1002,"lisi");"
# 把结果保存为文件
[bigdata@hadoop001 hive]$ bin/hive -e "select * from student;" > 1.txt
# 查看结果
[bigdata@hadoop001 hive]$ cat 1.txt
- 1. 在/hive目录下创建test.sql文件
[bigdata@hadoop001 hive]$ vim test.sql
// 文件中写入正确的sql语句
select * from student;
- 2. 执行文件中的sql语句
[bigdata@hadoop001 hive]$ bin/hive -f test.sql
- 3. 执行文件中的sql语句并将结果写入文件中
[bigdata@hadoop001 hive]$ bin/hive -f test.sql > hive_result.txt
hive>exit;
hive>quit;
exit:先隐性提交数据,再退出;
quit:不提交数据,退出;
hive> dfs -ls /;
hive> ! ls /opt/module/datas;
- 1. 进入到当前用户的根目录/root或/home/bigdata
[bigdata@hadoop001 hive]$ cd ~
- 2. 查看. hivehistory文件
[bigdata@hadoop001 ~]$ cat .hivehistory