Spark 1.4 connecting MySQL weird problems and solutions

Source: Internet
Author: User

MySQL data source connection is clearly configured in the spark-default.conf file

Then start Spark-shell execute the following test code:

Import Org.apache.spark. {sparkcontext, Sparkconf}import org.apache.spark.sql. {savemode, dataframe}import org.apache.spark.sql.hive.HiveContextval mysqlurl = "Jdbc:mysql://localhost:3306/yangsy ? user=root&password=yangsiyi "  val people_ddl = S" ""            CREATE temporary TABLE people            USING ORG.APACHE.SPARK.SQL.JDBC            options (              url    ' ${mysqlurl} ',              dbtable     ' person '            ) "". Stripmargin    sqlcontext.sql (PEOPLE_DDL)    val person = SQL ("SELECT * from people"). Cache () Val name = "Name" val Targets = Person.filter ("name =" +name). Collect ()

Collect () when the newspaper did not find driver

This is a very strange question. The data source connection is also true Ah, after all, in Hive's metastore also uses this AH. At the end of the day, the jar package can only be introduced at the start of Spark-shell =

./spark-shell--jars/usr/local/spark-1.4.0-bin-2.5.0-cdh5.2.1/lib/mysql-connector-java-5.1.30-bin.jar

Then the execution is OK. Weird..

Or a jar package that introduces MySQL before executing collect () can also

Sqlcontext.sql ("Add Jar/usr/local/spark-1.4.0-bin-2.5.0-cdh5.2.1/lib/mysql-connector-java-5.1.30-bin.jar")

But it always feels wrong. There is a solution to the guide ha ~

Spark 1.4 connecting MySQL weird problems and solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.