spark整合hive

● 准备好mysql
● 在spark的conf目录下创建一个hive的配置文件(hive-site.xml) :





  
    javax.jdo.option.ConnectionURL
    jdbc:mysql://hadoop-03:3306/hive?createDatabaseIfNotExist=true
    JDBC connect string for a JDBC metastore
  

   
    javax.jdo.option.ConnectionDriverName
    com.mysql.jdbc.Driver
    Driver class name for a JDBC metastore
  

  
    javax.jdo.option.ConnectionUserName
    root
    username to use against metastore database
  

  
    javax.jdo.option.ConnectionPassword
    root
    password to use against metastore database
  


● 上传mysql的驱动jar包,SparkSubmit需要获取mysql的元数据

● 启动命令

[root@hadoop-03 ~]# ./apps/spark-2.2.0/bin/spark-sql --master spark://hadoop-01:7077,hadoop-02:7077 --driver-class-path ./mysql-connector-java-5.1.39.jar

● 修改mysql表

sparkSQL会在mysql上创建一个database,需要手动改一下DBS表中的DB_LOCATION_UIR改成hdfs的地址

● 可以在spark-sql> 使用hive语法了

你可能感兴趣的:(spark)