hive常规配置及常用命令使用

hive 常用的几种shell交互方式

查看hive命令帮助:bin/hive -help

[hd@hadoop-senior 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,--helpPrint 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 shell交互界面,直接执行:

* bin/hive -e <quoted-query-string>
eg:
    bin/hive -e "select * from db_hive.student ;"

把sql脚本写入文件,通过 bin/hive -f 加载并执行脚本文件;通过bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt 可以把结果输出到指定文件

* bin/hive -f <filename>
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

与用户udf相互使用

* bin/hive -i <filename>

hive常见属性配置及命令

Hive数据仓库位置配置

default
        /user/hive/warehouse
    # 注意事项
        * 在仓库目录下,没有对默认的数据库default创建文件夹
        * 如果某张表属于default数据库,直接在数据仓库目录下创建一个文件夹

    # 在hive-site.xml中配置
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
    </property>

    # 并在hadoop中创建文件夹,并赋权限
      $ $HADOOP_HOME/bin/hadoop fs -mkdir       /tmp
      $ $HADOOP_HOME/bin/hadoop fs -mkdir       /user/hive/warehouse
      $ $HADOOP_HOME/bin/hadoop fs -chmod g+w   /tmp
      $ $HADOOP_HOME/bin/hadoop fs -chmod g+w   /user/hive/warehouse

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生效

在hive cli命令窗口中如何查看hdfs文件系统

hive (default)> dfs -ls / ;  

在hive cli命令窗口中如何查看本地文件系统

hive (default)> !ls /opt/datas ;
原文地址:https://www.cnblogs.com/tianboblog/p/8997636.html