故障现象:
数据库占用主机内存出奇的高,找了很久也找不到好的解决方法,如下:
数据版本:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.6.41-log Source distribution
[root@aaa~]# free -mh
total used free shared buffers cached
Mem: 3.8G 3.7G 121M 124K 4.6M 29M
-/+ buffers/cache: 3.7G 156M
Swap: 6.2G 5.7G 537M
内存占用非常高,重启后故障依旧。
原配置文件:
cat /etc/my.cnf
[mysqld]
#port = 3306
port = 65400
socket = /tmp/mysql.sock
datadir = /www/server/data
skip-external-locking
performance_schema_max_table_instances=400
table_definition_cache=400
key_buffer_size = 1024M
max_allowed_packet = 512M
table_open_cache = 1000
sort_buffer_size = 1M
net_buffer_length = 8K
以上三个红色的参数文件被称为5.6.X占用内存高的元凶,
参数调整如下:
[mysqld]
#port = 3306
port = 65400
socket = /tmp/mysql.sock
datadir = /www/server/data
skip-external-locking
#performance_schema_max_table_instances=400
performance_schema=OFF
table_definition_cache=400
key_buffer_size = 1024M
max_allowed_packet = 512M
table_open_cache = 1000
sort_buffer_size = 1M
net_buffer_length = 8K
重启数据库:
service mysqld restart
查看一下内存:
[root@feelingirldress ~]# free -mh
total used free shared buffers cached
Mem: 3.8G 985M 2.9G 204K 12M 229M
-/+ buffers/cache: 744M 3.1G
Swap: 6.2G 52M 6.2G
故障解决完成