# create user 'hive' identified by 'hive'
注:虽然可以直接使用root用户,但是推荐新建hive用户
2)更改hive用户的权限,刷新权限
# grant all privileges on *.* to 'hive'@'%' identified by 'hive' with grant option;
注:允许从任意地址登录的hive用户访问数据库中的任意内容
# flush privileges;
3)更改mysql的默认编码为utf8
# vi /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
#注意:两个字符集的设置分别在[mysql]和[mysqld]下,一定要正确对应
4)重启数据库(更改配置后重启服务是个好习惯)
# service mysql restart
(5.1版本以前的mysql服务命令是mysqld)
5)新建数据库,起名为hive(注意设置编码格式为latin1)
create database hive default character set latin1;
注:hive数据库一定要设置字符为latin1,因为它对其他字符的支持性不是很好
第二步:配置hive
1)上传hive
2)解压缩到HIVE_HOME
# tar -zxvf /root/hive_1.2.1 -C /apps
注:-z解压缩,-x解包,-v打印过程到控制台,-f使用归档文件,-C重定向
3)修改配置文件
# cp hive-default.xml.template hive-site.xml
注:hive默认配置文件就是hive-default.xml.template,拷贝修改即可
# vi hive-site.xml
<xml version="1.0" encoding="UTF-8" standalone="no"><xml-stylesheet type="text/xsl" href="configuration.xsl"><configuration><property><!-- 这是设置hive元数据的位置,是hdfs上的地址 --><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value><description>location of default database for the warehouse</description></property><property><!-- 设置mysql的地址,不一定要在本机
hive的本机模式只是说mysql服务和hive公用同一个jvm --><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://hadoop01:3306/hive</value></property><property><!-- 指定jdbc的驱动 --><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value></property><!-- 设置连接到数据库的用户名和密码 --><property><name>javax.jdo.option.ConnectionUserName</name><value>hive</value><description>username to use against metastore database</description></property><property><name>javax.jdo.option.ConnectionPassword</name><value>hive</value><description>password to use against metastore database</description></property></configuration>
4)配置并刷新环境变量
# vi /etc/profile
HIVE_HOME=/apps/hive
PATH=$PATH:$HIVE_HOME/bin
# source /etc/profile
Moved: 'hdfs://mini2:9000/user/hive/warehouse/demo.db' to trash at: hdfs://mini2:9000/user/root/.Trash/Current
解决: 检查mysql中的默认编码格式是否为latin1 过程: 查看日志后发现提示:
For direct MetaStore DB connections, we don't support retries at the client level.
尝试更换了mysql的驱动,发现没有用
最后才发现要删除mysql中的hive表,并重新建表:
# create database hive default character set latin1;
补充: 客户端上运行hive
1)客户端解压hive并配置环境变量
2)更改hive-site.xml
# vi hive-site.xml
<property>
<name>hive.metastore.uris</name>
<value>thrift://192.168.91.3:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore host</description>
</property>