HIVE之查缺补漏
Hive常用交互命令
- “-e”不进入hive的交互窗口执行sql语句
bin/hive -e "select id from student;"
- “-f”执行脚本中sql语句
-- 在/opt/module/datas目录下创建hivef.sql文件
touch hivef.sql
--文件中写入正确的sql语句
select *from student;
--执行文件中的sql语句
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql
--执行文件中的sql语句并将结果写入文件中
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql > /opt/module/datas/hive_result.txt
hive配置显示数据库名和表字段
在hive-site.xml文件中添加如下配置信息,就可以实现显示当前数据库,以及查询表的头信息配置。
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
高阶建表语句
- CTAS(复制表结构和数据):
create table 表1 as select * from 表2;
- CTAS(复制表结构):
create table 表1 as select