Spark 连接hive 元数据库(mysql)
方法一:
11)打开Hive metastore 2[root@head42 ~]# hive --service metastore & 3netstat -ano|grep 9083 ??? 42)开启spark连接Mysql 5[root@head42 ~]# spark-shell --conf spark.hadoop.hive.metastore.uris=thrift://localhost:9083 63)scala> spark.sql("show tables").show 7spark.sql("select * from database_name.table_name")//访问其他数据库 8+--------+--------------+-----------+ 9|database| tableName|isTemporary| 10+--------+--------------+-----------+ 11| default| customer| false| 12| default|text_customers| false| 13+--------+--------------+-----------+ 14这样就Ok了!
方法二:
1)拷贝hive的hive-site.xml文件到spark的conf目录下
2)修改spark中hive-site.xml文件
1添加以下: 2<configuration> 3<property> 4 <name>hive.metastore.uris</name> 5 <value>thrift://localhost:9083</value> 6</property> 7</configuration>
3)另建窗口启动:
[root@head42 conf]# hive --service metastore
4)启动spark:
[root@head42 conf]# spark-shell
5)测试:
1spark.sql("select * from database_name.table_name").show//访问其他数据库的表格 2scala> spark.sql("show tables").show 3+--------+--------------+-----------+ 4|database| tableName|isTemporary| 5+--------+--------------+-----------+ 6| default| customer| false| 7| default|text_customers| false| 8+--------+--------------+-----------+ 9这样就OK了!