Set命令
可以在Hive命令行中使用set
命令去临时设置一些参数的值,也就是hive-site.xml
文件中那些参数的值。
但通过这种方式设置的参数值只对当前会话有效。
也可以在脚本文件~/.hiverc
中配置set
命令,使得某些命令仅对当前机器的当前用户有效(~/.hiverc
文件需要自己创建)。
原创大约 2 分钟
可以在Hive命令行中使用set
命令去临时设置一些参数的值,也就是hive-site.xml
文件中那些参数的值。
但通过这种方式设置的参数值只对当前会话有效。
也可以在脚本文件~/.hiverc
中配置set
命令,使得某些命令仅对当前机器的当前用户有效(~/.hiverc
文件需要自己创建)。
查看Hive内置函数的信息的方法。
# 查看所有内置函数
hive (default)> show functions;
# 查看指定函数的信息
hive (default)> desc function <FUNC_NAME>;
# 查看指定函数的详细信息
hive (default)> desc function extended <FUNC_NAME>;
这是Hive默认的表类型,也称为受控表,表数据默认存储在/user/hive/warehouse
目录。
内部表
加载的数据都会被移动到/user/hive/warehouse
目录,而删除表时,表的元数据和数据都会被删除。
之前使用过的存储在Metastore
中的表都是内部表
。
Hive针对库的操作比针对表的操作要少,但操作表之前得先建库。
> cd /home/work/hive-3.1.3
> ./bin/hive
# 查看数据库列表
hive (default)> show databases;
# 创建数据库
hive (default)> create database testdb;
# 在指定位置创建数据库
hive (default)> create database testlocal location '/home/work/volumes/hive/testlocal'
# 选择数据库
hive (default)> use testdb;
# 删除数据库(默认数据库是无法删除的)
hive (default)> drop database testdb;
要想通过JDBC
代码的方式执行SQL
查询,需要先执行hiveserver2
命令。
> cd /home/work/hive-3.1.3
> ./bin/hiveserver2
......
执行下面的命令开启Hive客户端。
> cd /home/work/hive-3.1.3
> ./bin/hive
/usr/bin/which: no hbase in (/root/.local/bin:/root/bin:.:/home/work/hadoop-3.2.0/bin:/home/work/hadoop-3.2.0/sbin:/usr/local/java/jdk1.8.0_401/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/work/hive-3.1.3/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/work/hadoop-3.2.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive Session ID = 86ca643b-ec64-4f1f-bd24-6405e64fe77a
Logging initialized using configuration in jar:file:/home/work/hive-3.1.3/lib/hive-common-3.1.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.Hive Session ID = d8f39576-5efc-49c7-9658-1cf0b3b3cdca
hive>