Hive中常用命令:
1. 查看表的信息
show table tb_cxcc;
desc table tb_cxcc;
desc extended tb_cxcc;
desc formatted tb_cxcc;#这个命令展示出来的信息会很规整
创建表带格式
create table student (
id int
,name string
) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';# 制定存储时使用的分隔符
加载文件的数据到创建号的表中,可以时本地文件也可以时HDFS中的文件
load data local inpath '/root/data/student.txt' into table db_hive.student;
展示所有的函数
show functions;
展示函数的功能
desc function upper;
举例展示函数的功能
desc function extended upper;
在hive中直接操作dfs命令
dfs -rm -R /usr/hive/warehouse/bf_log
Hive数据仓库默认存储的位置
default
/user/hive/warehouse
注意:
* 在仓库目录下,没有对默认的数据库default创建文件夹
* 如果某个表在数据库default中,直接在数据仓库目录下创建一个文件夹代替
* 数据仓库的位置可以配置的,也可以在创建的DDL语句中指定。
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
下面时Hive的日志配置方法:
Hive运行日志信息位置
$HIVE_HOME/conf/hive-log4j.properties
hive.log.dir=/opt/modules/hive-0.13.1/logs
hive.log.file=hive.log
指定hive运行时显示的log日志的级别
$HIVE_HOME/conf/hive-log4j.properties
hive.root.logger=INFO,DRFA
在cli命令行上显示当前数据库,以及查询表的行头信息
$HIVE_HOME/conf/hive-site.xml
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>Whether to print the names of the columns in query output.</description>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive prompt.</description>
</property>
在启动hive时设置配置属性信息
$ bin/hive --hiveconf <property=value>
查看当前所有的配置信息
hive > set ;
hive (db_hive)> set system:user.name ;
system:user.name=beifeng
hive (db_hive)> set system:user.name=beifeng ;
此种方式,设置属性的值,仅仅在当前会话session生效
============================================================
查看启动前可以进行哪些设置信息
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
-h <hostname> connecting to Hive Server on remote host
--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
-p <port> connecting to Hive Server on port number
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)
Hive下几种常用的
交互式命令
:
1 bin/hive -e <quoted-query-string> //直接执行一个SQL语句
eg:
bin/hive -e "select * from db_hive.student ;"
2 bin/hive -f <filename> // 执行SQL脚本文件
eg:
$ touch hivef.sql
select * from db_hive.student ;
$ bin/hive -f /opt/datas/hivef.sql
$ bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt //将结果导入到某个文件中
3 bin/hive -i <filename> //这个文件时一个初始化用的SQL文件,通常与用户udf相互使用
在hive cli命令窗口中如何查看hdfs文件系统
hive (default)> dfs -ls / ;
在hive cli命令窗口中如何查看本地文件系统
hive (default)> !ls /opt/datas ;