3.hive常见命令

1 HiveJDBC访问

1.1 启动hiveServer2服务
[code1997@hadoop02 hive]$ bin/hiveserver2
1.2 开启beeline
[code1997@hadoop02 hive]$ bin/beeline

image-20210103221333188

1.3 简单使用

image-20210103221544136

2 Hive常见命令

2.1 常见的交互操作

使用bin/hive -help查看

[code1997@hadoop02 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,--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)

1)’-e’不进入hive的交互窗口执行sql

[code1997@hadoop02 hive]$ bin/hive -e 'select * from aa;'

image-20210103222632347

2)’-f’执行脚本中sql语句

[code1997@hadoop02 hive]$ touch hive.sql
[code1997@hadoop02 hive]$ vim hive.sql

hive.sql中内容:

select * from aa;

image-20210103223420348

执行文件中的sql语句并将结果写入到文件中:

[code1997@hadoop02 hive]$ bin/hive -f hive.sql >  hive_result.txt

image-20210103223724245

2.2 hive的其他命令操作

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

hive> dfs -ls /;

image-20210103224445590

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

hive> ! ls /opt/module/data;

image-20210103224215696

3)查看在 hive 中输入的所有历史命令

  • 查看root用户:[root@hadoop02 hive]# cat /root/.hivehistory
  • 查看其他用户:[code1997@hadoop02 hive]$ cat /home/code1997/.hivehistory
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.open(HiveMetaStoreClient.java:565) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.<init>(HiveMetaStoreClient.java:224) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient.<init>(SessionHiveMetaStoreClient.java:94) ~[hive-exec-3.1.3.jar:3.1.3] at sun.reflect.GeneratedConstructorAccessor20.newInstance(Unknown Source) ~[?:?] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_241] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_241] at org.apache.hadoop.hive.metastore.utils.JavaUtils.newInstance(JavaUtils.java:84) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.<init>(RetryingMetaStoreClient.java:95) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:148) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:119) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.metadata.Hive.createMetaStoreClient(Hive.java:4306) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:4374) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:4354) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.session.SessionState.setAuthorizerV2Config(SessionState.java:960) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.session.SessionState.setupAuth(SessionState.java:924) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hadoop.hive.ql.session.SessionState.applyAuthorizationPolicy(SessionState.java:1893) ~[hive-exec-3.1.3.jar:3.1.3] at org.apache.hive.service.cli.CLIService.applyAuthorizationConfigPolicy(CLIService.java:131) ~[hive-service-3.1.3.jar:3.1.3] at org.apache.hive.service.cli.CLIService.init(CLIService.java:115) ~[hive-service-3.1.3.jar:3.1.3] at org.apache.hive.service.CompositeService.init(CompositeService.java:59) ~[hive-service-3.1.3.jar:3.1.3] at org.apache.hive.service.server.HiveServer2.init(HiveServer2.java:229) ~[hive-service-3.1.3.jar:3.1.3] at org.apache.hive.service.server.HiveServer2.startHiveServer2(HiveServer2.java:1038) ~[hive-service-3.1.3.jar:3.1.3] ... 9 more
最新发布
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值