{"record":{"id":"e62e4fb3c8121ea0","repo":"apache/dolphinscheduler","slug":"execute-initialize-sql-file-sqlfilepath-e","errorCode":null,"errorMessage":"Execute initialize sql file: \" + sqlFilePath + \" error","messagePattern":"Execute initialize sql file: \" \\+ sqlFilePath \\+ \" error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/UpgradeDao.java","lineNumber":66,"sourceCode":"\n    @Autowired\n    private DbType dbType;\n\n    @Autowired\n    private DatabaseDialect databaseDialect;\n\n    /**\n     * run init sql to init db schema\n     */\n    public void initSchema() {\n        // Execute the dolphinscheduler full sql\n        String sqlFilePath = String.format(\"sql/dolphinscheduler_%s.sql\", dbType.getDb());\n        SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, sqlFilePath);\n        try {\n            sqlScriptRunner.execute();\n            log.info(\"Success execute the sql initialize file: {}\", sqlFilePath);\n        } catch (Exception ex) {\n            throw new RuntimeException(\"Execute initialize sql file: \" + sqlFilePath + \" error\", ex);\n        }\n    }\n\n    public String getCurrentVersion(String versionName) {\n        String sql = String.format(\"select version from %s\", versionName);\n        String version = null;\n        try (\n                Connection conn = dataSource.getConnection();\n                PreparedStatement pstmt = conn.prepareStatement(sql);\n                ResultSet rs = pstmt.executeQuery()) {\n            if (rs.next()) {\n                version = rs.getString(1);\n            }\n            return version;\n        } catch (SQLException e) {\n            log.error(\"Get current version from database error, sql: {}\", sql, e);\n            throw new RuntimeException(\"Get current version from database error, sql: \" + sql, e);\n        }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/UpgradeDao.java#L48-L84","documentation":"UpgradeDao.initSchema executes sql/dolphinscheduler_<dbType>.sql via SqlScriptRunner to initialize the schema. Any exception while executing that SQL file (connection failure, syntax error, pre-existing tables) is rethrown as a RuntimeException 'Execute initialize sql file: <path> error' with the original exception as cause.","triggerScenarios":"Calling initSchema when sqlScriptRunner.execute() fails: the classpath resource sql/dolphinscheduler_<db>.sql is missing, the DB connection fails mid-script, a statement errors (object already exists, insufficient privileges, unsupported SQL for the dialect), or the script partially applied then failed.","commonSituations":"Running init-schema on a database that already has DolphinScheduler tables (duplicate table errors); missing sql files in the packaged jar; DB user lacking CREATE privileges; using a database type whose SQL file is incompatible or absent.","solutions":["Read the cause exception to find the failing SQL statement, and fix that specific issue (drop conflicting objects or fix privileges).","Verify sql/dolphinscheduler_<dbType>.sql exists on the classpath for your database type.","Grant the DB user CREATE/DDL privileges, or run as a DBA account during init.","If the script partially applied, drop the partially created objects (or use a clean schema) and re-run init."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify the sql resource and empty target before init\nassert UpgradeDao.class.getClassLoader().getResource(\"sql/dolphinscheduler_mysql.sql\") != null : \"init sql file missing from classpath\";\n// verify target schema has no existing DolphinScheduler tables","typeGuard":null,"tryCatchPattern":"try {\n    upgradeDao.initSchema();\n} catch (RuntimeException e) {\n    log.error(\"Schema init failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e);\n    // inspect cause for the failing SQL statement before retrying\n}","preventionTips":["Run init only against a clean/empty schema.","Verify the sql/ resources are packaged in the jar for your DB type.","Use a DB account with CREATE privileges for init.","Test the init script against a scratch database first."],"tags":["database","sql","schema-init"],"backgroundTag":"sql-query-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}