注意:
1、hive和sql一样是大小写不敏感的,因此对于SHOW TABLES;和show tables;命令效果是一样的
2、hive -f script.q可以用来执行包含命令的脚本文件
hive -e ‘select * from dummy’可以直接用来执行较短的hive语句
一、Hive的配置文件属性设置
hive --config /users/tom/dev/hive-conf
重新定义hive查找hive-site.xml文件的路径,在配置文件中使用HIVE_CONF_DIR选项指定到相应的路径可以有相同的效果,适用于多个集群之间相互切换
hive -hiveconf fs.default.name=localhost -hiveconf mapred.job.tracker=localhost:8021
为单个会话设置属性,该属性默认是从hive-site.xml中读取
SET hive.enforce.bucketing=true
为特定的需求来专门的设定配置属性
SET hive.enforce.bucketing
可以用来查询对应属性的属性值
SET
显示所有的属性以及属性值,不包括hadoop的默认属性值
SET -v
可以列出系统中所有的属性和属性值,包含hadoop的默认属性值
hive -hiveconf hive.root.logger=DEBUG,console
可以将调试信息方便的发送到控制台
设置属性有一个优先级层次,分别是
SET,-hiveconf,hive-site.xml,hive-default.xml,hadoop-site.xml,hadoop-default.xml
二、Metastore
内嵌metastore
一次只能为每个metastore打开一个hive会话,如果试着启动第二个会话,在它试图连接metastore时,会得到以下的错误信息,Failed to start database 'metastore_db'
本地metastore
hive.metastore.warehouse.dir
默认值是/user/hive/warehouse,相对于fs.default.name的目录,托管表就存储在这里
hive.metastore.local=true
javax.jdo.option.ConnectionURL=jdbc:mysql://host/dbname?createDatabaseIfNotExist=true
javax.jdo.option.ConnectionDriveName=com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName=连接数据库的用户名
javax.jdo.option.ConnectionPassword=连接数据库对应用户名的密码
将JDBC驱动的jar文件放到Hive的lib目录
远程metastore
hive.metastore.warehouse.dir
默认值是/user/hive/warehouse,相对于fs.default.name的目录,托管表就存储在这里
hive.metastore.local=false
hive.metastore.uris=设置为metastore服务器URI,如果有多个服务器,中间使用逗号分隔,URI的形式为thrift://host:port
javax.jdo.option.ConnectionURL=jdbc:mysql://host/dbname?createDatabaseIfNotExist=true
javax.jdo.option.ConnectionDriveName=com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName=连接数据库的用户名
javax.jdo.option.ConnectionPassword=连接数据库对应用户名的密码
将JDBC驱动的jar文件放到Hive的lib目录
将hive服务设置为远程metastore,使用hive --service 命令
三、数据类型
复杂数据类型声明必须使用尖括号指明其中的数据类型
create table complex{
col1 array<int>
col2 map<string,int>
col3 struct<a:string,b:int,c:double>
}
四、操作与函数
show functions
可以显示所有hive中内置函数的信息
describe function length
显示具体某个函数的一些使用信息