1.1 数据库导出和导入
1.1.1 Mysql
1.1.1.1 手动
1. 客户端命令行工具
导出命令窗口:
mysqldump -h 127.0.0.1 -P 3306 -u root-proot db1>d://dbName1.sql --default-character-set=utf8
导入
mysql -h 127.0.0.1 -P 3306 -u root -proot db1<d://dbName1.sql--default-character-set=utf8
或
mysql -h 127.0.0.1 -P 3306 -u root –proot;
use db1;
source d://dbName1.sql;
1.1.1.2 java导入数据
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.Properties;
/**
* 利用mysql客户端命令行工具
* @author cl
* @since 2015-04-27
*
*/
public class MysqlUtil {
public static void main(String args[]) throws IOException {
exec(createDataBaseCommand("db1"),useDataBaseCommand("db1"),sourceCommand("d://db1.sql"));
exec(dropDataBaseCommand("db1"));
}
/**
* 执行命令
* @param commands
* @throws IOException
*/
public static void exec(String... commands) throws IOException{
exec(loadProperties(),commands);
}
private static Properties loadProperties() throws IOException{
URL path= MysqlUtil.class.getClassLoader().getResource("jdbc.properties");
InputStream is = path.openStream();
Properties propertie