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
我有一个巨大的SQL文件,我想恢复到mysql服务器5.5 ....当我恢复过程中恢复过程中的文件停止,然后我有一个想法,使用java将该文件拆分为几个文件。 ..是谁知道如何将SQL文件拆分成几个文件.....以下代码是我创建的java类来拆分SQL文件...这个类可以为每个行创建sql large file一个文件“哪个不可用”,我想拆分SQL文件,这样我就可以拥有能够在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());
}
}
}
3 个解决方案
#1
0
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.
只是问,因为根据我的经验,使用SOURCE命令通过MySQL控制台或类似操作很容易。至少高达50-60mb。
#3
0
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
实际上没有必要将文件拆分成几个文件并将它们存储到数据库...我找到了一种方法,你可以将数据库恢复到使用mysql命令的mysql
here is the command that i used:
这是我使用的命令:
mysql - u user_name -p your_password database_name < file_name.sql
mysql - u user_name -p your_password database_name
it works for me ...
这个对我有用 ...
#1
0
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.
只是问,因为根据我的经验,使用SOURCE命令通过MySQL控制台或类似操作很容易。至少高达50-60mb。
#2
#3
0
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
实际上没有必要将文件拆分成几个文件并将它们存储到数据库...我找到了一种方法,你可以将数据库恢复到使用mysql命令的mysql
here is the command that i used:
这是我使用的命令:
mysql - u user_name -p your_password database_name < file_name.sql
mysql - u user_name -p your_password database_name
it works for me ...
这个对我有用 ...