MySQL数据库优化总结
- - CSDN博客推荐文章 对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要. 一般来说,要保证数据库的效率,要做好以下四个方面的工作:数据库设计、sql语句优化、数据库参数配置、恰当的硬件资源和操作系统,这个顺序也表现了这四个工作对性能影响的大小. 一、数据库设计
适度的反范式,注意是适度的.
mysql> desc statistics_news_category_history; +---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | id | int(10) | NO | PRI | NULL | auto_increment | | news_category | varchar(20) | YES | | NULL | | | news_num | int(10) | YES | | NULL | | | news_date | varchar(10) | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
mysql> select * from statistics_news_category_history procedure analyse(9,256)\G; *************************** 1. row *************************** Field_name: datacrawldb.statistics_news_category_history.id Min_value: 26 Max_value: 30 Min_length: 2 Max_length: 2 Empties_or_zeros: 0 Nulls: 0 Avg_value_or_avg_length: 28.0000 Std: 1.4142 Optimal_fieldtype: TINYINT(2) UNSIGNED NOT NULL *************************** 2. row *************************** Field_name: datacrawldb.statistics_news_category_history.news_category Min_value: bigdata Max_value: test Min_length: 4 Max_length: 10 Empties_or_zeros: 0 Nulls: 0 Avg_value_or_avg_length: 6.6000 Std: NULL Optimal_fieldtype: ENUM('bigdata','cloud','datacenter','storage','test') NOT NULL *************************** 3. row *************************** Field_name: datacrawldb.statistics_news_category_history.news_num Min_value: 1 Max_value: 33 Min_length: 1 Max_length: 2 Empties_or_zeros: 0 Nulls: 0 Avg_value_or_avg_length: 19.4000 Std: 11.9766 Optimal_fieldtype: TINYINT(2) UNSIGNED NOT NULL *************************** 4. row *************************** Field_name: datacrawldb.statistics_news_category_history.news_date Min_value: 2014-02-17 Max_value: 2014-02-17 Min_length: 10 Max_length: 10 Empties_or_zeros: 0 Nulls: 0 Avg_value_or_avg_length: 10.0000 Std: NULL Optimal_fieldtype: ENUM('2014-02-17') NOT NULL 4 rows in set (0.00 sec)