问题描述
我正在运行此版本的Mysql
Ver 14.14 Distrib 5.6.24, for debian-linux-gnu (x86_64)
在此版本的Ubuntu
Distributor ID: Ubuntu
Description: Ubuntu 15.04
Release: 15.04
Codename: vivid
这是我为Mysql设置的配置:
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
innodb_buffer_pool_size=20G
innodb_log_buffer_size=16M
tmp_table_size = 32M
max_heap_table_size = 32M
open-files-limit=4510
max_connections=500
myisam-recover = BACKUP
query_cache_type=1
query_cache_limit = 32M
query_cache_size = 32M
这些是我在启动MYSQL时不断收到的警告:
2015-06-17 17:28:53 26720 [Warning] Buffered warning: Could not increase number
of max_open_files to more than 1024 (request: 4510)
2015-06-17 17:28:53 26720 [Warning] Buffered warning: Changed limits: max_connections:
214 (requested 500)
2015-06-17 17:28:53 26720 [Warning] Buffered warning: Changed limits: table_open_cache:
400 (requested 2000)
我已经尝试了以下步骤:
1)将其添加到/etc/security/limits.conf
mysql soft nofile 65535
mysql hard no file 65535
2)将其添加到/etc/pam.d/common-auth
和/etc/pam.d/commom-session
session required pam_limits.so
3)将此添加到/etc/mysql/mysql.conf.d/mysqld.cnf
open-files-limit=4510 or open_files_limit=4510
这些都不起作用,我仍然无法将mysql最大连接数提高到500。
在这一点上,我非常感谢您的帮助。
非常感谢。
最佳思路
Ubuntu已从版本15.04的Upstart迁移到Systemd,并且不再遵守/etc/security/limits.conf中的系统服务限制。这些限制现在仅适用于用户会话。
MySQL服务的限制在Systemd配置文件中定义,您应该将其从默认位置复制到/etc /systemd中,然后编辑该副本。
sudo cp /lib/systemd/system/mysql.service /etc/systemd/system/
sudo vim /etc/systemd/system/mysql.service # or your editor of choice
将以下行添加到文件的底部:
LimitNOFILE=infinity
LimitMEMLOCK=infinity
您也可以设置数字限制,例如LimitNOFILE=4510
。
现在,使用以下命令重新加载Systemd配置:
sudo systemctl daemon-reload
重新启动MySQL,它现在应遵守max_connections指令。
升级到15.04后,我也无法完全停止MySQL。如果这对您造成影响(您会知道,因为执行service mysql stop
或service mysql restart
会花费300秒的超时时间),然后将以下行添加到相同的/etc/systemd/system/mysql.service文件中,该文件已为我修复:
ExecStop=/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown
后一个问题似乎已由16.04修复,并且不再需要此行,因此在进行发行版升级之前,您将要停止MySQL并从配置文件中删除ExecStop
行。
次佳思路
从MySQL 5.7.7开始,这是该文档对Red Hat Enterprise Linux 7,Oracle Linux 7,CentOS 7,SUSE Linux Enterprise Server 12,Fedora 24和25的建议:
https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
在Ubuntu 16.04上,该服务称为mysql,而不是mysqld,所以这就是我所做的:
sudo mkdir /etc/systemd/system/mysql.service.d
sudo vi /etc/systemd/system/mysql.service.d/override.conf
在新文件override.conf中添加了它:
[Service]
LimitNOFILE=5000
然后重新启动服务:
sudo systemctl daemon-reload
sudo systemctl restart mysql
第三种思路
我建议您不要按照建议的那样复制现有的mysql.service文件,只需创建一个仅包含您关心的更改的文件即可。这样:
mkdir /lib/systemd/system/mysql.service.d
vim /etc/systemd/system/mysql.service.d/limits.conf
而且limits.conf的内容很简单:
[Service]
LimitNOFILE=10000
LimitMEMLOCK=10000
或您喜欢的任何限制。