# Set HADOOP_HOME to point to a specific hadoop install directory HADOOP_HOME=/usr/local/Cellar/hadoop/2.6.0
# Hive Configuration Directory can be controlled by: export HIVE_CONF_DIR=/usr/local/Cellar/hive/1.0.0/libexec/conf
# Folder containing extra ibraries required for hive compilation/execution can be controlled by: export HIVE_AUX_JARS_PATH=/usr/local/Cellar/hive/1.0.0/libexec/lib
<property> <name>hive.querylog.location</name> <value>/usr/local/Cellar/hive/1.0.0/log</value> <description>Location of Hive run time structured log file</description> </property> <property> <name>hive.exec.scratchdir</name> <value>/tmp/hive-${user.name}</value> <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: $ {hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description> </property> <property> <name>hive.exec.local.scratchdir</name> <value>/tmp/${user.name}</value> <description>Local scratch space for Hive jobs</description> </property> <property> <name>hive.downloaded.resources.dir</name> <value>/tmp/${user.name}_resources</value> <description>Temporary local directory for added resources in the remote file system.</description> </property> <property> <name>hive.server2.logging.operation.log.location</name> <value>/tmp/${user.name}/operation_logs</value> <description>Top level directory where operation logs are stored if logging functionality is enabled</description> </property>
安装mysql
1 2 3 4 5 6 7 8 9
$ brew install mysql
$ mysql.server start #启动mysql $ mysql -uroot #root用户进入mysql
mysql> CREATE DATABASE metastore; mysql> USE metastore; mysql> CREATE USER 'hive'@'localhost' IDENTIFIED BY 'hive'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,ALTER,CREATE ON metastore.* TO 'hive'@'localhost';
启动hadoop服务
1
$ $HODOOP_HOME/sbin/start-dfs.sh #启动hdfs
启动hive
1 2 3 4
$ /usr/local/Cellar/hive/1.0.0/bin/hive
在~/.zshrc 设置快捷方式 alias hive='/usr/local/Cellar/hive/1.0.0/bin/hive'
#3. Hive Shell命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#显示所有的数据表 hive>show tables; #创建一个表,这个表包括两列,分别是整数类型以及字符串 类型,使用文本文件表达,数据域之间的分隔符为\t hive> create table shakespeare (freq int, word string) row format delimited fields terminated by ‘\t’ stored as textfile; #显示所创建的数据表的描述,即创建时候对于数据表的定义 hive> describe shakespeare; 数据装入到Hive中 hive> load data inpath “shakespeare_freq” into table shakespeare; #SELECTS and FILTERS hive> select * from shakespeare limit 10; hive> SELECT a.foo FROM invites a WHERE a.ds='2008-08-15'; #Group by hive> INSERT OVERWRITE TABLE events SELECT a.bar, count(*) FROM invites a WHERE a.foo > 0 GROUP BY a.bar; #Join hive> SELECT t1.bar, t1.foo, t2.foo FROM pokes t1 JOIN invites t2 ON t1.bar = t2.bar;