美文网首页大数据笔记
Hive 2.1 - Hive shell 操作

Hive 2.1 - Hive shell 操作

作者: No_七 | 来源:发表于2019-10-25 14:14 被阅读0次

    1、hive shell 帮助

    [root@hadoop06 hive-1.2.2-bin]# 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
    
    1.1 指定要使用的数据库

    --database <databasename>

        [root@hadoop06 hive-1.2.2-bin]# bin/hive --database db01
        Logging initialized using configuration in file:/opt/app/hive-1.2.2-bin/conf/hive-log4j.properties
        OK
        Time taken: 0.7 seconds
        hive (db01)>
    
    1.2直接执行sql

    -e <quoted-query-string>

        [root@hadoop06 hive-1.2.2-bin]# bin/hive -e "show databases"
        Logging initialized using configuration in file:/opt/app/hive-1.2.2-bin/conf/hive-log4j.properties
        OK
        database_name
        db01
        db02
        default
        Time taken: 0.886 seconds, Fetched: 3 row(s)
    
    1.3 执行文件内的sql

    -f <filename>

        [root@hadoop06 hive-1.2.2-bin]# bin/hive -f /opt/datas/hive.file
        Logging initialized using configuration in file:/opt/app/hive-1.2.2-bin/conf/hive-log4j.properties
        OK
        database_name
        db01
        db02
        default
        Time taken: 0.871 seconds, Fetched: 3 row(s)
    
    1.4 其他命令
     -H,--help                        Print help information
        --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
     -S,--silent                      Silent mode in interactive shell
     -v,--verbose                     Verbose mode (echo executed SQL to the
                                      console)
    

    2、查看本地目录信息:

    hive (default)> !ls /;
    

    3、查看HDFS目录信息

    相当于 [root@hadoop06 hadoop-2.5.0]# bin/hdfs dfs -ls /; 但是hive命令的效率会高

    hive (db01)> dfs -ls /;
    Found 2 items
    drwx-wx-wx   - root supergroup          0 2018-11-14 15:04 /tmp
    drwxr-xr-x   - root supergroup          0 2018-11-14 11:49 /user
    

    4、在HDFS上操作文件

    hive (db01)> dfs -mkdir -p /test; 
    hive (db01)> dfs -rm -r /test;
    

    相关文章

      网友评论

        本文标题:Hive 2.1 - Hive shell 操作

        本文链接:https://www.haomeiwen.com/subject/gapsvctx.html