Importing a (mysql) database dump programmatically through Java

前端 未结 4 1332
终归单人心
终归单人心 2020-12-15 20:21

How can I import a mysql database dump file (contains insert and create table statements) programmatically through a java program. I need this as the setup phase of a unit t

4条回答
  •  北海茫月
    2020-12-15 21:02

    You could start a new process from java and execute this command if you have access to the mysql executable wherever you are running the import. Something like this:

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("mysql -p -h ServerName DbName < dump.sql");
    

提交回复
热议问题