Getting MySQL table size with PHP
2009-08-19 18:18
288 查看
Below is a small script that lets you read the table sizes of a MySQL database.
<?php
$link = mysql_connect('host', 'username', 'password');
$db_name = "your database name here";
$tables = array();
mysql_select_db($db_name, $link);
$result = mysql_query("SHOW TABLE STATUS");
while($row = mysql_fetch_array($result)) {
/* We return the size in Kilobytes */
$total_size = ($row[ "Data_length" ] +
$row[ "Index_length" ]) / 1024;
$tables[$row['Name']] = sprintf("%.2f", $total_size);
}
print_r($tables);
?> |
Array ( [wp_comments] => 80.00 [wp_links] => 48.00 [wp_options] => 224.00 [wp_pollsa] => 16.00 [wp_pollsip] => 16.00 [wp_pollsq] => 16.00 [wp_postmeta] => 48.00 [wp_posts] => 112.00 [wp_term_relationships] => 32.00 [wp_term_taxonomy] => 32.00 [wp_terms] => 48.00 [wp_usermeta] => 48.00 [wp_users] => 48.00 ) |
相关文章推荐
- Getting all selected rows in ADF Table with multiple rows selection enabled
- MySQL优化经验 key_buffer_size, query_cache_size, table_cache
- mysql优化的重要参数  key_buffer_size  table_cache
- Some issues with php mysql install
- WITH (NOLOCK) table hint equivalent for MySQL
- Mysql 1293 - Incorrect table definition; there can be only one TIMESTAMP column with C
- Creating a Code Search Engine with PHP and MySQL(1)
- Web Database Applications with PHP & MySQL, 2nd Edition [ILLUSTRATED]
- Dump data into MySQL from Excel with PHP
- php SQL Injection with MySQL
- PHP + mysql 遇到Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error
- Using Memcache with MySQL and PHP
- mysql的tmp_table_size和max_heap_table_size
- mysql 的内存临时表两个参数 tmp_table_size、max_heap_table_size
- MySQLTable By Table Backup With Auto Rotation, For Easy Restoration Of Partial/Full Database
- Mysql调优中两个重要参数table_cache和key_buffer_size
- How to Integrate angular 2 with php and mysql db
- Getting Started with PHPUnit
- Getting Started with the Table Component
- mysql的tmp_table_size和max_heap_table_size