mysql dump.sql大小写转换

案例:

从公司的mysql导出数据库后,在linux下导入mysql,应用程序sql语句大小写导致的问题:

 

  1. 导出mysql(windows): mysqldump -h host -u userName -p password>dump.sql
  2. linux下导入到mysql:
    mysql -u root -p
    mysql>source ~/dump.sql
  3. 运行程序发现报错:linux下表名区分大小写导致所有的sql不正常(应用中都是大写的sql)
  4. 写代码解决此问题
  5. 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();
    		}
    	}
     

     

你可能感兴趣的:(sql,linux,windows,mysql)