1,查询mysql/ target=_blank class=infotextkey>mysql数据库大小的方法一,使用INFORMATION_SCHEMA:
复制代码 代码示例:
select (sum(data_length) + sum(index_length))/(1024*1024) from INFORMATION_SCHEMA.`TABLES` where table_schema = 'your_table_schema' and table_name like
'your_table_name';
2,查询mysql数据库大小的方法二,
show table status like '';
复制代码 代码示例:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("url", "user", "pwd");
Statement stat = conn.createStatement();
stat.executeUpdate("use your_db");
String sql = "show table status like 'your_table_name'";
ResultSet rs = stat.executeQuery(sql);
while (rs.next()) {
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getString(i + 1) + " ");
}
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}
代码说明:
以上代码打印出表的相关信息,将相关字段相加即可得到数据库的大小。