mysql - 无法通过节俭获取配置单元远程 Metastore 表信息

标签 mysql hadoop hive derby thrift

我可以使用以下程序获取本地 mysql 元存储设置中的元存储表信息以及配置单元。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;

public class MetaStoreTest {

    public static void main(String[] args) throws Exception {

        Connection conn = null;
        try {
            HiveConf conf = new HiveConf();
            conf.addResource(new Path("/home/hadoop/hive-0.12.0/conf/hive-site.xml"));
            Class.forName(conf.getVar(ConfVars.METASTORE_CONNECTION_DRIVER));
            conn = DriverManager.getConnection(
                    conf.getVar(ConfVars.METASTORECONNECTURLKEY),
                    conf.getVar(ConfVars.METASTORE_CONNECTION_USER_NAME),
                    conf.getVar(ConfVars.METASTOREPWD));

            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(
                "select t.tbl_name, s.location from TBLS t " +
                "join SDS s on t.sd_id = s.sd_id");
            while (rs.next()) {
                System.out.println(rs.getString(1) + " : " + rs.getString(2));
            }
        }
        finally {
            if (conn != null) {
                conn.close();
            }
        }

    }
}

目前我正在尝试使用上面的程序使用节俭从远程元存储获取元存储表。在我当前的 hive-site.xml 中,我有这些参数,

hive.metastore.uris = thrift://host1:9083, thrift://host2:9083
hive.metastore.local = false

没有参数:

javax.jdo.option.ConnectionDriverName, javax.jdo.option.ConnectionUserName, javax.jdo.option.ConnectionPassword

那么,我如何通过节俭协议(protocol)获取元表信息。我在 host2 上运行上面的代码。请提出建议。

另外,当我运行上面的代码时,它会显示以下信息:

METASTORE_CONNECTION_DRIVER as derby connection embedded driver, 
METASTORECONNECTURLKEY as jdbc:mysql://<host name>/<database name>?createDatabaseIfNotExist=true, 
METASTORE_CONNECTION_USER_NAME as "APP" and 
METASTOREPWD as "mine"

最佳答案

替换这部分代码:

conf.addResource(new Path("/home/hadoop/hive-0.12.0/conf/hive-site.xml"));
Class.forName(conf.getVar(ConfVars.METASTORE_CONNECTION_DRIVER));
conn = DriverManager.getConnection(
       conf.getVar(ConfVars.METASTORECONNECTURLKEY),
       conf.getVar(ConfVars.METASTORE_CONNECTION_USER_NAME),
       conf.getVar(ConfVars.METASTOREPWD));

以下:

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://host2:3306/metastore", "urusername", "urpassword");

[注意:根据您的设置相应地更改 Metastore 数据库名称、用户和密码。]

现在:

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("show tables");
while (rs.next()) {
   System.out.println("Tables:" +rs.getString(1));
}

看看你是否获得了 Metastore 表名。

关于mysql - 无法通过节俭获取配置单元远程 Metastore 表信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31400783/

相关文章:

php - 我无法将数据显示代码中的变量传递给另一个数据库代码(这与数据库连接)

java - 在Java中根据时间戳获取HDFS文件

sql - 通过匹配SQL中的列值来联接两个表

hadoop - Hive:使用脚本添加的资源在 Hortonworks 中被清除了吗?

mysql - SQL 乘以所有先前行的值

mysql - 根据现有数据插入/更新mysql列

php - 在 Codeigniter 中使用 JOIN 时回显来自特定表的记录

hadoop - HBase Thrift 文件结束异常

hadoop - HBase的主无法启动

database - HBase 或 Hive - 网络请求