I have a huge SQL file that I want to restore to mysql server 5.5 …. while I’m restoring the the file at the middle of restoring process stopped, then i got an idea to split that file to several files using java … is anybody got the the idea how to split the SQL file into several files …..
the following code is for the java class that i create to split the SQL file… this class can create for each line in the sql huge file a file”which is not usable”, i would like to split the SQL file so i can have files which is able to be restored in the mysql-server
import java.io.*;
import java.io.FileWriter;
class DataBase
{
public static void main(String args[]){
try{
FileInputStream fstream = new FileInputStream("D:/dewiki-20110831-site_stats.sql");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
File f;
int i=1;
while ((strLine = br.readLine()) != null){
f=new File("D:/myfile"+i+".sql");
if(!f.exists()){
f.createNewFile();
PrintWriter out = new PrintWriter(new FileWriter(f));
out.write(strLine);
out.close();
}
System.out.println (strLine);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
actually there is no need to split the file into several files and store them to the database …
i found a way where you can restore the database to mysql which is using mysql commands
here is the command that i used:
mysql – u user_name -p your_password database_name < file_name.sql
it works for me …