Hive笔记--安装
http://blog.csdn.net/superye1983
Hive的安装其实很简单下载tar包解压,然后配置一下HIVE_HOME和系统PATH就可以了
然后运行hive
Logging initialized using configuration in jar:file:/home/kira/src/hive/current/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/kira/hive_job_log_kira_201209101140_767693934.txt
看到以上信息就可以开始在命令行中使用Hive了
先试一下show tables;
结果报错:
FAILED: Error in metadata: javax.jdo.JDOFatalInternalException: Error creating transactional connection factory
NestedThrowables:
java.lang.reflect.InvocationTargetException
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
这个错误出现的原因是Hive自带的lib中没有mysql的jar,我用的是mysql-connector-java-5.1.18-bin.jar,拷贝到HIVE_HOME/lib中
再运行,还是报错,这次错误信息不一样了
FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true;characterEncoding=UTF-8;createDatabaseIfNotExist=true' is not in this set.
NestedThrowables:
java.sql.SQLException: The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true;characterEncoding=UTF-8;createDatabaseIfNotExist=true' is not in this set.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
这个提示还是很明确的,找到hive-site.xml中的
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?useUnicode=true;characterEncoding=UTF-8;createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
修改为
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?useUnicode=true&characterEncoding=UTF-8&createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
好了继续跑
又出错了
FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Access denied for user 'root'@'localhost' (using password: YES)
NestedThrowables:
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
这次坑爹了,从terminal运行mysql -uroot -p是可以进去的呀
看了一下hive-site.xml,配置mysql用户名密码的信息为:
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value></value>
<description>password to use against metastore database</description>
</property>
没错呀我的用户名是root,密码为空
然后就是查是否是权限开放的有问题,于是各种GRANT,改user表,都试了一遍还是不行
由于我有很多其他项目在本地都是用的root和空这套用户名密码,所以从一开始就不想换用户名密码,也就导致所有的修改都没能成功的原因
后来想到是否是javax.jdo.option.ConnectionPassword配置为空导致hive的程序使用了NULL而非空字符串做密码呢
于是只能添加新的用户名密码了
进去mysql:mysql -uroot -p
输入密码
use mysql;
insert into user(Host,User,Password) values("localhost","hive",password("hive"));
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'localhost' IDENTIFIED BY 'hive' WITH GRANT OPTION;
FLUSH PRIVILEGES;
然后修改hive-site.xml
<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>
再run,总算OK了
到此为止总算是能跑了,最后那个问题应该是和密码为空有关,但是否是上面所说的被hive改为了NULL,这点没有看源码,以后再认证吧!
我的hive版本hive-0.8.1