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

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了!
伊卡洛斯丿银精治树
山川异域,风月同天。
2
发布数
0
关注者
993
累计阅读

热门教程文档

Lua
21小节
C++
73小节
Kotlin
68小节
Java
12小节
Typescript
31小节
广告