MySQL内存占用


看了一下VPS的控制台,发现内存使用量爆表,swap空间也用了不少

在终端输入top,按下大写M,查看内存使用量排名,发现mysql占了58%内存

于是决定对mysql的配置进行修改,以节约内存,参考网上的文章,配置文件最终修改如下

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format=mixed
server-id = 1

# Disabling symbolic-links is recommended 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
[mysqldump] quick max_allowed_packet = 16M
[mysql] no-auto-rehash
[myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 2M

修改之后内存瞬间富裕了好多

发表评论

邮箱地址不会被公开。 必填项已用*标注