合适mysql 5.6与5.7运行内存主要参数提升运行内存

2021-03-15 06:22 jianzhan
合适mysql 5.6与5.7运行内存主要参数提升运行内存占有为30MB上下 Whyfine • 2019 年 12 月 02 日

表明:mysql 5.6、5.7默认设置起动占有运行内存400多M,假如是vps等小运行内存运用,mysql运行内存占有率显著较高,可能造成奔溃,mysql会全自动终止。
编写/etc/f文档在[mysqld]下提升或改动以下主要参数

performance_schema_max_table_instances = 200
table_definition_cache = 100
table_open_cache = 100。

这一三个主要参数,调低值后运行内存能显著减少,如今mysql应用运行内存约60MB上下,就大大的减少默认设置应用的运行内存。

进一步伐整主要参数

innodb_buffer_pool_size=2M

这一三个主要参数能够调小。 再进一步伐整: mysql 5.6默认设置开启performance_schema,占有许多运行内存,能够禁止使用。

详细配备文档以下,运行内存占有到22M

我的mysql配备以下,假如你应用的centos6 64位,而且是yum安裝的(一键脚本制作)能够自身依照以下照搬,我的是centos6 64位系统软件

先ssh登陆网络服务器或VPS,在vi /etc/f

# For advice on how to change settings please see
# 
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#symbolic-links=0
skip-external-locking
key_buffer_size = 8M
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64k高清
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
#innodb_use_native_aio = 0
innodb_buffer_pool_size=2M
performance_schema_max_table_instances=50
table_definition_cache=50
table_open_cache=32
max_connections=50
max_user_connections=35
wait_timeout=10
interactive_timeout=15
long_query_time=5
# Disabling symbolic-links mended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

默认设置值以下:

performance_schema_max_table_instances 12500
table_definition_cache 1400
table_open_cache 2000