导出mysql(windows): mysqldump -h host -u userName -p password>dump.sql
linux下导入到mysql:
mysql -u root -p
mysql>source ~/dump.sql
运行程序发现报错:linux下表名区分大小写导致所有的sql不正常(应用中都是大写的sql)
写代码解决此问题
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("/home/skzrorg/dump.sql"));
BufferedWriter writer = new BufferedWriter(new FileWriter("/home/skzrorg/dump2.sql"));
System.out.println("开始转换");
try {
Pattern pattern = Pattern.compile("`\\w+`");
StringBuffer buf = new StringBuffer();
while(reader.ready()) {
buf.setLength(0);
String v = reader.readLine();
Matcher matcher = pattern.matcher(v);
while(matcher.find()) {
matcher.appendReplacement(buf, matcher.group().toUpperCase());
}
matcher.appendTail(buf).append("\r\n");
writer.write(buf.toString());
}
System.out.println("成功转换");
} finally {
writer.close();
}
}