统计数据库大小
SELECT table_schema , sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
统计表大小并排序
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'zabbix'
ORDER BY (data_length + index_length) DESC;
$(which mysql) -u${User} -p${Passwd} -e "
use zabbix;
DELETE FROM history WHERE 'clock' < $Date;
optimize table history;
DELETE FROM history_str WHERE 'clock' < $Date;
optimize table history_str;
DELETE FROM history_uint WHERE 'clock' < $Date;
optimize table history_uint;
DELETE FROM trends WHERE 'clock' < $Date;
optimize table trends;
DELETE FROM trends_uint WHERE 'clock' < $Date;
optimize table trends_uint;
DELETE FROM events WHERE 'clock' < $Date;
optimize table events;
该参数定义了数据缓冲区buffer pool大小,类似于oracle的db_cache_size
mysql> show global variables like 'innodb_buffer_pool_size'; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | innodb_buffer_pool_size | 134217728 | +-------------------------+-----------+ 1 row in set (0.00 sec)
那么如何设置该参数大小呢?首先查看运行时buffer pool相关数据指标:
mysql> show global status like 'Innodb_buffer_pool_pages_data'; +-------------------------------+-------+ | Variable_name | Value | +-------------------------------+-------+ | Innodb_buffer_pool_pages_data | 314 | +-------------------------------+-------+ 1 row in set (0.00 sec)
mysql> show global status like 'Innodb_buffer_pool_pages_total'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | Innodb_buffer_pool_pages_total | 8191 | +--------------------------------+-------+ 1 row in set (0.00 sec)
mysql> show global status like 'Innodb_page_size'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | Innodb_page_size | 16384 | +------------------+-------+ 1 row in set (0.00 sec)
上述三项指标的含义如下:
Innodb_buffer_pool_pages_data The number of pages in the InnoDB buffer pool containing data. The number includes both dirty and clean pages.
Innodb_buffer_pool_pages_total The total size of the InnoDB buffer pool, in pages.
Innodb_page_size InnoDB page size (default 16KB). Many values are counted in pages; the page size enables them to be easily converted to bytes