第68课 Spark sql 通过JDBC 操作 Mysql 每天晚上20:00YY频道现场授课频道68917580

来源:互联网 发布:淘宝怎么登陆不了 编辑:程序博客网 时间:2024/05/01 06:50
/* * *王家林老师授课http://weibo.com/ilovepains */  

每天晚上20:00YY频道现场授课频道68917580




输入
mysql> select * from  dthadoop ;
+---------+------+
| name    | age  |
+---------+------+
| Michael |   12 |
| Andy    |   23 |
| Justin  |   34 |
| spark   |   99 |
+---------+------+




mysql> select * from dtspark;
+---------+-------+
| name    | score |
+---------+-------+
| Michael |    45 |
| Andy    |   100 |
| Justin  |    91 |
| spark   |    99 |


运行结果




mysql> select * from nameagescore ;
+---------+------+-------+
| name    | age  | score |
+---------+------+-------+
| Michael |   12 |    45 |
| spark   |   99 |    99 |
| Andy    |   23 |   100 |
| Justin  |   34 |    91 |
+---------+------+-------+




截图























1.在mysql中建立表


-- ----------------------------
-- Table structure for dthadoop
-- ----------------------------
DROP TABLE IF EXISTS `dthadoop`;
CREATE TABLE `dthadoop` (
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `age` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


-- ----------------------------
-- Records of dthadoop
-- ----------------------------
INSERT INTO `dthadoop` VALUES ('Michael', '12');
INSERT INTO `dthadoop` VALUES ('Andy', '23');
INSERT INTO `dthadoop` VALUES ('Justin', '34');
INSERT INTO `dthadoop` VALUES ('spark', '99');


-- ----------------------------
-- Table structure for dtspark
-- ----------------------------
DROP TABLE IF EXISTS `dtspark`;
CREATE TABLE `dtspark` (
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `score` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


-- ----------------------------
-- Records of dtspark
-- ----------------------------
INSERT INTO `dtspark` VALUES ('Michael', '45');
INSERT INTO `dtspark` VALUES ('Andy', '100');
INSERT INTO `dtspark` VALUES ('Justin', '91');
INSERT INTO `dtspark` VALUES ('spark', '99');









DROP TABLE IF EXISTS `nameagescore`;
CREATE TABLE `nameagescore` (
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `score` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;






2.权限
grant all privileges on *.* to root@'master'  identified by  'root';




3.代码编写


4.执行脚本
root@master:/usr/local/spark-1.6.0-bin-hadoop2.6/lib# /usr/local/spark-1.6.0-bin-hadoop2.6/bin/spark-submit --class 


com.dt.spark.IMFSQL.SparkSQLJDBC2MySql --driver-class-path /usr/local/setup_tools/mysql-connector-java-5.1.13-


bin.jar  --master local /usr/local/IMF_testdata/SparkSQLJDBC2Mysql.jar































0 0
原创粉丝点击