2024.6.14

对 hive 本地mysql 远程 mysql 的读取

public class SparkSQL07_Source_MySQL {
    public static void main(String[] args) {

        // TODO 构建环境对象
        //      Spark在结构化数据的处理场景中对核心功能,环境进行了封装
        //      构建SparkSQL的环境对象时,一般采用构建器模式
        //      构建器模式: 构建对象
        final SparkSession sparkSession = SparkSession
                .builder()
                .master("local[*]")
                .appName("SparkSQL")
                .getOrCreate();


        Properties properties = new Properties();
        properties.setProperty("user", "root");
        properties.setProperty("password", "123456");

//        json.write()
//                // 写出模式针对于表格追加覆盖
//                .mode(SaveMode.Append)
//                .jdbc("jdbc:mysql://hadoop102:3306","gmall.testInfo",properties);

//        Dataset<Row> jdbc = sparkSession.read()
//                .jdbc("jdbc:mysql://node1:3306/hive?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "AUX_TABLE", properties);

        Dataset<Row> jdbc = sparkSession.read()
                .jdbc("jdbc:mysql://localhost:3306/endwork?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai", "t2", properties);

//        jdbc.write()
//                .jdbc("jdbc:mysql://localhost:3306/endwork?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai", "activity_info_test", properties);

        jdbc.show();

        // TODO 释放资源
        sparkSession.close();

    }
}

但是今天 启动hive的时候 出了点问题 ??

posted @ 2024-06-14 23:38  258333  阅读(15)  评论(0编辑  收藏  举报