Home  >  Article  >  Database  >  Innodb优化之修改页大小

Innodb优化之修改页大小

WBOY
WBOYOriginal
2016-06-07 17:40:101536browse

MySQL在使用innodb引擎的时候页大小默认是16K,这个大小对于很多应用来说太大了,很多在其他数据如ORACLE运行良好的应用迁移到innodb后发现IO压力偏大,MySQL本

MySQL在使用innodb引擎的时候页大小默认是16K,美国服务器,这个大小对于很多应用来说太大了,很多在其他数据如ORACLE运行良好的应用迁移到innodb后发现IO压力偏大,MySQL本身没有提供修改页大小的参数,但是我们可以通过修改源码重新编译mysql来实现,下面来做个测试,做测试的数据库版本为mysql-5.5.25:

 先查看当前的页大小:

mysql> SHOW GLOBAL STATUS like 'Innodb_page_size';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Innodb_page_size | 16384 |
+------------------+-------+
1 row in set (0.00 sec)

mysql>

可以看到默认情况下mysql的页大小为16k,下面修改页面大小相关的源码

vim /mysql-5.5.25/storage/innobase/include/univ.i

#define UNIV_WORD_ALIGNMENT     UNIV_WORD_SIZE

/*
                        DATABASE VERSION CONTROL
                        ========================
*/

/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT    14                           ------------这个变量是修改为13
/* The universal page size of the database */
#define UNIV_PAGE_SIZE          (1

 

修改完成后代码应该是:

#define UNIV_WORD_ALIGNMENT     UNIV_WORD_SIZE

/*
                        DATABASE VERSION CONTROL
                        ========================
*/

/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT    13                          

/* The universal page size of the database */
#define UNIV_PAGE_SIZE          (1

对于mysql 5.1的版本代码和5.5的修改方式稍微不同,下面的5.1版本代码的修改方式:

/*
   DATABASE VERSION CONTROL
   ========================
*/

/* The universal page size of the database */
#define UNIV_PAGE_SIZE          (2 * 8192) /* NOTE! Currently, this has to be a ------修改为(2*4096)     

power of 2 */
/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT 14   ------修改为13(该值是2的多少次方为UNIV_PAGE_SIZE)

/* Maximum number of parallel threads in a parallelized operation */
#define UNIV_MAX_PARALLELISM 32

     修改红色部分即可,记住UNIV_PAGE_SIZE大小只能是2的次方,如8K,16K,32k,UNIV_PAGE_SIZE_SHIFT 该值是2的多少次方为UNIV_PAGE_SIZE。

修改完成保存退出然后重新编译安装Mysql数据库,虚拟主机,过程就不写了。编译安装完成后再次查看页大小:

mysql>
mysql> SHOW GLOBAL STATUS like 'Innodb_page_size';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Innodb_page_size | 8192  |
+------------------+-------+
1 row in set (0.00 sec)

mysql>

可以看到页大小已经修改为8K。


 

,香港空间
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn