日期:2014-05-20 浏览次数:20794 次
public static void load(String fileName) throws Exception {
String username = "root";
String password = "root3306";
String mysqlpath = "D:\\DeveloperTools\\MySQL\\MySQL Server 5.6\\bin\\";
String databaseName = "nasystem";
String address = "localhost";
String sqlpath = "D:\\";
// 建立数据库
String createDatabase = mysqlpath + "mysqladmin -u" + username + " -p"
+ password + " create " + databaseName;
// 还原数据库数据
String loadData = mysqlpath + "mysql -h " + address + " -u"
+ username + " -p" + password + " " + databaseName + " < "
+ sqlpath + fileName;
System.out.println("建立数据库:" + createDatabase);
System.out.println("还原数据:" + loadData);
Runtime r = Runtime.getRuntime();
r.exec(createDatabase);
r.exec(loadData);
}