开发者

splitting a huge sql file to multiple sql files

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 PrintWr开发者_高级运维iter(new FileWriter(f));

  out.write(strLine);

  out.close();

  }

  System.out.println (strLine);

  i++;

  }

  in.close();

    }catch (Exception e){

  System.err.println("Error: " + e.getMessage());

  }

  }

}


Just wondering why the process interrupts halfway through? How are you importing the database?

Just asking because from what I've experienced it's easy to do through the MySQL console or similar using the SOURCE command. At least up to 50-60mb.


Try using mysqldbimport instead.


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 ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜