缓冲警告:更改限制:max_connections:214(要求 800)

Buffered warning: Changed limits: max_connections: 214 (requested 800)

每次我重新启动 MySQL 我都会收到这个警告:

[Warning] Buffered warning: Changed limits: max_connections: 214 (requested 800)

所以我必须更改 max_connections 变量:

set global max_connections = 800;

但是 /etc/my.cf 设置了 max_connections

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
max_connections = 800

我也修改了mysqld.service:

# Start main service
ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf

我还将 Centos 的最大打开文件数从 1024 更新为 2000:

ulimit -Sa | grep "open files"
open files                      (-n) 2000

但问题依旧。

Mysql 日志开始:

150924 13:15:04 mysqld_safe mysqld from pid file 

/var/run/mysqld/mysqld.pid ended
150924 13:15:04 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2015-09-24 13:15:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-09-24 13:15:04 0 [Note] /usr/sbin/mysqld (mysqld 5.6.25) starting as process 29997 ...
2015-09-24 13:15:04 29997 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2015-09-24 13:15:04 29997 [Warning] Buffered warning: Changed limits: max_connections: 214 (requested 800)

2015-09-24 13:15:04 29997 [Warning] Buffered warning: Changed limits: table_open_cache: 400 (requested 2000)

2015-09-24 13:15:04 29997 [Note] Plugin 'FEDERATED' is disabled.
2015-09-24 13:15:04 29997 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-09-24 13:15:04 29997 [Note] InnoDB: The InnoDB memory heap is disabled
2015-09-24 13:15:04 29997 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-09-24 13:15:04 29997 [Note] InnoDB: Memory barrier is not used
2015-09-24 13:15:04 29997 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-09-24 13:15:04 29997 [Note] InnoDB: Using Linux native AIO
2015-09-24 13:15:04 29997 [Note] InnoDB: Using CPU crc32 instructions
2015-09-24 13:15:04 29997 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-09-24 13:15:04 29997 [Note] InnoDB: Completed initialization of buffer pool
2015-09-24 13:15:04 29997 [Note] InnoDB: Highest supported file format is Barracuda.
2015-09-24 13:15:04 29997 [Note] InnoDB: 128 rollback segment(s) are active.
2015-09-24 13:15:04 29997 [Note] InnoDB: Waiting for purge to start
2015-09-24 13:15:04 29997 [Note] InnoDB: 5.6.25 started; log sequence number 24337684937
2015-09-24 13:15:04 29997 [Note] Server hostname (bind-address): '*'; port: 3306
2015-09-24 13:15:04 29997 [Note] IPv6 is available.
2015-09-24 13:15:04 29997 [Note]   - '::' resolves to '::';
2015-09-24 13:15:04 29997 [Note] Server socket created on IP: '::'.
2015-09-24 13:15:04 29997 [Note] Event Scheduler: Loaded 0 events
2015-09-24 13:15:04 29997 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.25'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

我尝试了所有 Google 解决方案,但结果总是一样...

MySQL 在 CentOS Linux 版本 7.1.1503(核心)上是 运行。

谢谢!

刚刚花了一两个小时在使用 MySQL 5.6.26 的 CentOS 7 上面对完全相同的问题,这是我的解决方案。 除了提高最大打开文件数(对于 mysql 用户),看起来你已经完成了,你还需要添加 "LimitNOFILE=65535" (或类似的,取决于你想要的限制有多高设置) 到您的 mysql.service 定义文件。

所以对我来说完整的解决方案如下

将这两行附加到 /etc/security/limits.conf

mysql hard nofile 65535
mysql soft nofile 65535

将此行附加到 /usr/lib/systemd/system/mysqld.service(在 [service] 部分)

LimitNOFILE=65535

然后最后重新启动并检查这些错误消息是否已从您的 mysql 错误日志中消失。

编辑:感谢@SieGeL 提醒我添加,如果您直接更新“.service”文件,您的编辑将在升级时丢失。要在升级后保留编辑,请通过在 /etc/systemd/system/mysqld.service.d

中创建一个额外的 conf 文件来使用 systemd 覆盖

我不建议编辑原始的 systemd 文件,因为它会在更新过程中被覆盖。

要修改限制,请执行以下操作:

mkdir /etc/systemd/system/mysqld.service.d

在该目录中,创建新文件 limits.conf 并将以下内容添加到该文件:

[Service]
  LimitNOFILE = 65535

最后重新加载 systemd:

systemctl daemon-reload

并重新启动 mysqld 以启用更改:

systemctl restart mysqld

现在使用以下查询验证更改是否成功:

mysql> show variables like '%file%';

你应该找到这样一行:

| open_files_limit                      | 65535  

就是这样,这样您的更改就会在 MySQL 更新后继续存在。

对我来说(mariadb 1:10.3.23-0+deb10u1 在 Debian Buster 上)Changed limits 警告的原因是 none 的 OS 限制(似乎 Debian 安装程序会自动增加文件限制,具体取决于在 my.cnf 中的 open_file_limit 变量上) ...

我有:

open_files_limit        = 185000
table_open_cache        = 185000
table_definition_cache  = 185000
innodb_open_files       = 185000

my.cnf 中,但在启动时它们发生了变化:

MariaDB [(none)]> select @@open_files_limit, @@table_open_cache, @@table_definition_cache, @@innodb_open_files;
+--------------------+--------------------+--------------------------+---------------------+
| @@open_files_limit | @@table_open_cache | @@table_definition_cache | @@innodb_open_files |
+--------------------+--------------------+--------------------------+---------------------+
|             185000 |              92460 |                   185000 |              185000 |
+--------------------+--------------------+--------------------------+---------------------+

引起我注意的是 table_open_cache 大约是我设置的一半...

有趣的是,我可以输入 mysql 客户端并将其设置为 set global table_open_cache = 185000 没有问题。

原来 MariaDB 用一些更合理的东西覆盖了我的配置

/var/log/syslog中有线索:

[Warning] Changed limits: max_open_files: 185000  max_connections: 50 (was 50)  table_cache: 92460 (was 185000)

我的解决方案只是将所有变量设置为两倍以上 (400000),因此我的 table_open_cache 至少会在 185000 我想要的位置。