MySQL import data from SQL Server export file

I need to import into a MySQL database some data that has previously been exported from a SQL Server 2008 database.

The SQL Server export has been made into a SQL file, and export file format looks like this:

INSERT [table1] ([column1], [column2], [column3]) VALUES (1351801, 1548565, N'/*******************************************************************************
 *
 *******************************************************************************/

package chap1;

public class Main {
    public static void main(String[] args) {
        System.out.println("lala");
    }
}
')
INSERT [table_name] ([column1], [column2], [column3]) VALUES (1351851, 154865, N'/*******************************************************************************
 *
 *******************************************************************************/

package chap2;

public class Implementation1 implements Interface1 {

    @Override
    public void go() {
    }

}
')

Note that column3 contains some Java Source code.

I try to load this data into MySQL using the command:

source table1_export.sql;

Of course, I have noticed that this is not MySQL insert syntax and I have tried to change this to the correct MySQL syntax. But, this also fails when loading the data for column3, which contains Java code and could have some special characters that MySQL doesn't like.

Any of what I can do to load the data from the file into MySQL?


Using Mysql Import Service you can achieve this easily from a .sql database dump file.

String jdbcConnectionUrl = "jdbc:mysql://localhost:3306/yourDatabaseName?useSSL=false";

try {
            String sql = new String(Files.readAllBytes(Paths.get("your .sql dump file path")));
            MysqlImportService service = MysqlImportService.builder()
                .setDatabase(databaseName)
                .setSqlString(sql)
                .setUsername('your database username)
                .setPassword('your database password')
                .setDeleteExisting(true)
                .setDropExisting(true)
                .setJdbcDriver(configuration.getDriver())
                .setJdbcConnString(jdbcConnectionUrl).build();
            service .importDatabase();
        }
        catch (IOException | SQLException | ClassNotFoundException e) {
            e.printStackTrace();
         }