[mysql] mysql memory configuration tuning

 

 

mysql's memory calculation formula:

mysql used mem = key_buffer_size + query_cache_size + tmp_table_size
+ innodb_buffer_pool_size + innodb_additional_mem_pool_size
+ innodb_log_buffer_size
+ max_connections * (
read_buffer_size + read_rnd_buffer_size
+ sort_buffer_size+ join_buffer_size
+ binlog_cache_size + thread_stack
)

 

 

Enter the following command in mysql to find out the total amount of memory and the configuration of each parameter:

SET @kilo_bytes = 1024;
SET @mega_bytes = @kilo_bytes * 1024;
SET @giga_bytes = @mega_bytes * 1024;

SELECT
( @@key_buffer_size + @@query_cache_size + @@tmp_table_size
+ @@innodb_buffer_pool_size + @@innodb_additional_mem_pool_size
+ @@innodb_log_buffer_size
+ @@max_connections * (
@@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size
+ @@join_buffer_size + @@binlog_cache_size + @@thread_stack
) ) / @giga_bytes AS MAX_MEMORY_GB;

select @@key_buffer_size / @mega_bytes;
select @@query_cache_size / @mega_bytes;
select @@innodb_buffer_pool_size / @mega_bytes;
select @@innodb_additional_mem_pool_size / @mega_bytes;
select @@innodb_log_buffer_size / @mega_bytes;
select @@read_buffer_size / @mega_bytes;
select @@read_rnd_buffer_size / @mega_bytes;
select @@sort_buffer_size / @mega_bytes;
select @@join_buffer_size / @mega_bytes;
select @@binlog_cache_size / @mega_bytes;
select @@thread_stack/ @mega_bytes;
select @@max_connections;

 

 

Parameter configuration:

Configure the corresponding parameters in the [mysqld] section in /etc/mysql/my.cnf, such as:

max_connections = 128
innodb_buffer_pool_size = 2G

 Reference link: http://blog.sina.com.cn/s/blog_47186b8b0100vp5n.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326675463&siteId=291194637