Spark���������������mysql���������������
������������������������������mysql���������������������
������������
���������
[root@head42 spark]# spark-shell --jars /opt/spark/jars/mysql-connector-java-5.1.38.jar
���������
val df=spark.read.format("jdbc").option("delimiter",",").option("header","true").option("url","jdbc:mysql://192.168.56.103:3306/test").option("dbtable","customer").option("user","root").option("password","ok").load()#"dbtable":mysql������df.show
���������������java.sql.SQLException: No suitable driver
���������
[root@head42 ~]# cd /opt/hive/lib/[root@head42 lib]# cp mysql-connector-java-5.1.38.jar /opt/spark/jars/
���������������������������
============================================================
������������
���������sqoop,������sqoop
#!/bin/bashsqoop import \--connect jdbc:mysql://localhost:3306/test \ #test:mysql������������--table table_name \ --username root \--password ok \--target-dir /data/mydata13 \ #���������������������hdfs���������-m 1 #���������������
���������hive������������������������������������������������hdfs���������
create external table orders(order_id int,order_date timestamp,order_customer_id int,order_status string)row format delimitedfields terminated by ','location '/data/mydata1'
���������������������������������������spark������������������������
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:90833���scala> spark.sql("show tables").showspark.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������
���������������hive.metastore.uris thrift://localhost:9083
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������