Innodb最佳化之修改頁大小

來源:互聯網
上載者:User

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 << UNIV_PAGE_SIZE_SHIFT)  --------這個變數就是Innodb頁的大小,1左移13位剛好是8192。

 

修改完成後代碼應該是:

#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 << UNIV_PAGE_SIZE_SHIFT) 

對於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。


 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.