Hive使用MySQL存放元数据
可以参考一下这篇文章
http://www.mazsoft.com/blog/post/2010/02/01/Setting-up-HadoopHive-to-use-MySQL-as-metastore.aspx
别忘了下载 MySQL 的JDBC驱动,推荐下载 mysql-connector-java-5.1.11.tar.gz
Hive 与 JDBC
导入hive\lib下的所有jar包到IDE的classpath里面,还有hadoop中的 hadoop-0.20.2-core.jar包,即可运行下列代码:
package com.javabloger.hive;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class HiveTestCase {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
String dropSQL="drop table javabloger";
String createSQL="create table javabloger (key int, value string)";
String insterSQL="LOAD DATA LOCAL INPATH '/work/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE javabloger";
String querySQL="SELECT a.* FROM javabloger a";
Connection con = DriverManager.getConnection("jdbc:hive://192.168.20.213:10000/default", "", "");
Statement stmt = con.createStatement();
stmt.executeQuery(dropSQL); // 执行删除语句
stmt.executeQuery(createSQL); // 执行建表语句
stmt.executeQuery(insterSQL); // 执行插入语句
ResultSet res = stmt.executeQuery(querySQL); // 执行查询语句
while (res.next()) {
System.out.println("Result: key:"+res.getString(1) +" –> value:" +res.getString(2));
}
}
}