hive general configuration and common command usage

Several shell interaction methods commonly used in hive

View hive command help: 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)

Without entering the hive shell interactive interface, execute directly:

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

Write the sql script to a file,  load and execute the script file through bin/hive -f; through bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt The result can be output to the specified document

* 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

Interoperate with user udf

* bin/hive -i <filename>

hive common attribute configuration and commands

Hive data warehouse location configuration

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 run log information location

$HIVE_HOME/conf/hive-log4j.properties
        hive.log.dir=/opt/modules/hive-0.13.1/logs
        hive.log.file=hive.log

Specifies the level of log logs displayed when hive is running

$HIVE_HOME/conf/hive-log4j.properties
        hive.root.logger=INFO,DRFA

Display the current database on the cli command line, as well as the row header information of the query table

$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>

Set configuration property information when starting hive

$ bin/hive --hiveconf <property=value>

View all current configuration information

hive > set ;

    hive (db_hive)> set system:user.name ;
        system:user.name=beifeng
    hive (db_hive)> set system:user.name=beifeng ;

    此种方式,设置属性的值,仅仅在当前会话session生效

How to view hdfs file system in hive cli command window

hive (default)> dfs -ls / ;  

How to view local file system in hive cli command window

hive (default)> !ls /opt/datas ;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343267&siteId=291194637