标签:play query localhost des cal driver ati rip pos
hive的远程模式,mysql连接配置。
<property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value><!--mysql的user--> <description>Username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>mypassword</value><!--mysql的password--> <description>password to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value><!--jdbc驱动--> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.25.66:3306/hive?characterEncoding=UTF-8&createDatabaseIfNotExist=true&useSSL=false</value> <description> JDBC connect string for a JDBC metastore. To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL. For example, jdbc:postgresql://myhost/db?ssl=true for postgres database. </description>
</property>
<property> <!--表示任意节点使用hadoop集群用户root都能访问hdfs--> <name>hadoop.proxyuser.root.hosts</name> <value>*</value> </property> <property> <name>hadoop.proxyuser.root.groups</name> <value>*</value> </property>
这里的adoop.proxyuser.root.hosts和hadoop.proxyuser.root.group代表hive当前可访问的超级user。
注意点:修改完hadoop的core-site.xml配置文件后 必须重启hadoop;
若是关闭hadoop出现This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh,这代表hadoop无法关闭。
可以手动jps查看进程,然后通过:kill -9 进程id 手动杀死所有进程。
然后通过start-all.sh重启hadoop。
beeline的path:$HIVE_HOME/bin/beeline
beeline -u jdbc:hive2://localhost:10000/default -n root -p 这里的root就是adoop.proxyuser.root.hosts和hadoop.proxyuser.root.group里的root
注意:在这不部分直接执行beeline命令可能会提示拒绝连接,
hive --service metastore & hive --service hiveserver2 &
3. 最终结果:
如上图所示;代表hive连接成功。
测试code如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class APP {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main( String[] args )
{
try {
Class.forName(driverName);
Connection con = null;
con = DriverManager.getConnection("jdbc:hive2://myhost:10000/hive0331", "root", "");
Statement stmt = con.createStatement();
ResultSet res = null;
String sql = "select * from users";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
System.out.println("ok");
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2) + "\t" + res.getString(3) );
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("error");
}
}
}
可以参考:Apache Hive :https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-UsingJDBC
标签:play query localhost des cal driver ati rip pos
原文地址:https://www.cnblogs.com/hcxss/p/14611504.html