一、HiveJDBC访问
1)启动beeline客户端
bin/beeline -u jdbc:hive2://hadoop101:10000 -n caron
2)看到如下界面
Connecting to jdbc:hive2://hadoop101:10000
Connected to: Apache Hive (version 3.1.2)
Driver: Hive JDBC (version 3.1.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 3.1.2 by Apache Hive
0: jdbc:hive2://hadoop101:10000>
二、Hive访问
1)启动hive客户端
bin/hive
2)看到如下界面
which: no hbase in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/module/jdk1.8.0_212/bin:/opt/module/hadoop-3.1.3/bin:/opt/module/hadoop-3.1.3/sbin:/opt/module/hive/bin:/home/atguigu/.local/bin:/home/atguigu/bin)
Hive Session ID = 36f90830-2d91-469d-8823-9ee62b6d0c26
Logging initialized using configuration in jar:file:/opt/module/hive/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
Hive Session ID = 14f96e4e-7009-4926-bb62-035be9178b02
hive>
3)打印 当前库 和 表头
在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 -help
usage: hive
-d,–define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
–database Specify the database to use
-e SQL from command line
-f 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 Initialization SQL file
-S,–silent Silent mode in interactive shell
-v,–verbose Verbose mode (echo executed SQL to the console)
1)“-e”不进入hive的交互窗口执行sql语句
bin/hive -e "select id from student;"
2)“-f”执行脚本中sql语句
(1)在/opt/module/hive/下创建datas目录并在datas目录下创建hivef.sql文件
touch hivef.sql
(2)文件中写入正确的sql语句
select *from student;
(3)执行文件中的sql语句
bin/hive -f /opt/module/hive/datas/hivef.sql
(4)执行文件中的sql语句并将结果写入文件中
bin/hive -f /opt/module/hive/datas/hivef.sql > /opt/module/datas/hive_result.txt
四、 Hive其他命令操作
1)退出hive窗口:
hive(default)>exit;
hive(default)>quit;
在新版的hive中没区别了,在以前的版本是有的:
exit:先隐性提交数据,再退出;
quit:不提交数据,退出;
2)在hive cli命令窗口中如何查看hdfs文件系统
hive(default)>dfs -ls /;
3)查看在hive中输入的所有历史命令
(1)进入到当前用户的根目录/root或/home/caron
(2)查看. hivehistory文件
cat .hivehistory