Increase memory usage for InnoDB MySQL database to improve p_MySQL

WBOY
풀어 주다: 2016-05-31 08:49:37
원래의
1041명이 탐색했습니다.

If your MySQL database tables still run on the MyISAM engine (formerly the default), you may want to consider switching to the InnoDB engine instead, for better reliability and scalability. To update a table from MyISAM to InnoDB you can run this SQL:

ALTER TABLE table_name ENGINE = InnoDB;
로그인 후 복사

Once you’ve switched all your tables to InnoDB, you can adjust some memory usage settings.

Update MySQL memory usage settings for InnoDB

Firstly, check the current settings for innerdb_buffer_pool_size . You can view these settings by running the following SQL (you can run this in phpMyAdmin):

SHOW VARIABLES;
로그인 후 복사
로그인 후 복사

Look for innerdb_buffer_pool_size . You’ll see it’s been assigned a particular number of bytes. This allocated cache stores table and index data, and keeps queries and query results in memory for faster lookup. So the more memory you can afford to dedicate to it the better – MySQL recommends to use 80% of the available memory. You can read about it here .

I had 2GB of server memory to play with, so I chose a moderate 1GB to allocate to the innerdb_buffer_pool_size . To add this setting, we’ll create and load our own custom MySQL cnf file, which will house some extra settings.

On Linux Ubuntu , add a new cnf file here:

sudo nano /etc/mysql/conf.d/innodb.cnf
로그인 후 복사

The file name must end in .cnf , but call it whatever you like, so long as it’s not clashing with another file name.

Inside of this file, we add our new memory allocation:

[mysqld]innodb_buffer_pool_size = 1024Mkey_buffer_size = 8M
로그인 후 복사

I’ve also added a new key_buffer_size value of 8MB. If you’ve deprecated your use of the MyISAM engine, it’s recommended to reduce this memory allocation. Previously I had 16M for key_buffer_size , so I decided to half it.

Finish off by restarting MySQL so that the changes can be applied:

sudo service mysql restart
로그인 후 복사

If you check the MySQL variables once more:

SHOW VARIABLES;
로그인 후 복사
로그인 후 복사

You’ll hopefully now have some new and importantly increased memory values for innodb_buffer_pool_size and key_buffer_size

innodb_buffer_pool_size

myisam_key_buffer_size

You’ve successfully optimised your MySQL database a bit more!

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!