text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Connection conn = null;
String url = "jdbc:mysql://ip地址:3306/数据库名&user=用户名&password=密码&useUnicode=true&characterEncoding=UTF8";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String sql = "SHOW TABLE STATUS FROM `数据库名`;";
ResultSet rs = stmt.executeQuery(sql);
HashSet<String> tables=new HashSet<String>();
while (rs.next()) {
String tname =rs.getString("Name");
tables.add(tname);
}
rs.close();
for(String tb:tables){
stmt.execute("optimize table "+tb);
}
stmt.close();
转载于:https://my.oschina.net/jingshishengxu/blog/3089201

评论
登录后即可评论
分享你的想法,与作者互动
暂无评论