Spark 配置连接hive 元数据库(mysql)

Spark 连接hive 元数据库(mysql)

方法一:

1)打开Hive metastore
[root@head42 ~]# hive --service metastore &
netstat -ano|grep 9083   ???
2)开启spark连接Mysql
[root@head42 ~]# spark-shell --conf spark.hadoop.hive.metastore.uris=thrift://localhost:9083
3)scala> spark.sql("show tables").show
spark.sql("select * from database_name.table_name")//访问其他数据库
+--------+--------------+-----------+
|database|     tableName|isTemporary|
+--------+--------------+-----------+
| default|      customer|      false|
| default|text_customers|      false|
+--------+--------------+-----------+
这样就Ok了!

方法二:

1)拷贝hive的hive-site.xml文件到spark的conf目录下

2)修改spark中hive-site.xml文件

添加以下:
<configuration>
<property>
  <name>hive.metastore.uris</name>
 <value>thrift://localhost:9083</value>
</property>
</configuration>

3)另建窗口启动:

[root@head42 conf]# hive --service metastore

4)启动spark:

[root@head42 conf]# spark-shell

5)测试:

spark.sql("select * from database_name.table_name").show//访问其他数据库的表格
scala> spark.sql("show tables").show
+--------+--------------+-----------+
|database|     tableName|isTemporary|
+--------+--------------+-----------+
| default|      customer|      false|
| default|text_customers|      false|
+--------+--------------+-----------+
这样就OK了!
原文地址:https://www.cnblogs.com/tudousiya/p/11387823.html