1 HiveJDBC访问
1.1 启动hiveServer2服务
[code1997@hadoop02 hive]$ bin/hiveserver2
1.2 开启beeline
[code1997@hadoop02 hive]$ bin/beeline
1.3 简单使用
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;'
2)’-f’执行脚本中sql语句
[code1997@hadoop02 hive]$ touch hive.sql
[code1997@hadoop02 hive]$ vim hive.sql
hive.sql中内容:
select * from aa;
执行文件中的sql语句并将结果写入到文件中:
[code1997@hadoop02 hive]$ bin/hive -f hive.sql > hive_result.txt
2.2 hive的其他命令操作
1)在 hive cli 命令窗口中如何查看 hdfs 文件系统
hive> dfs -ls /;
2)在 hive cli 命令窗口中如何查看本地文件系统
hive> ! ls /opt/module/data;
3)查看在 hive 中输入的所有历史命令
- 查看root用户:[root@hadoop02 hive]# cat /root/.hivehistory
- 查看其他用户:[code1997@hadoop02 hive]$ cat /home/code1997/.hivehistory