缓冲区警告:更改限制:max_connections:214(请求800)。

18

每次我重新启动MySQL时都会出现以下警告:

[警告] 缓冲警告:更改的限制:max_connections:214(请求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)

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

MySQL运行在CentOS Linux release 7.1.1503 (Core)上。

谢谢!


对我来说看起来还不错。请看此处 - Bernd Buffen
做了吗...但是什么都没有发生... - Valerio Paoletti
3个回答

22

我刚刚在CentOS 7上遇到了与MySQL 5.6.26相关的相同问题,经过一两个小时的努力,这是我的解决方案。除了提高最大打开文件数(对于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 below提醒我添加,如果直接更新“.service”文件,则在升级时将丢失您的编辑。为了在升级后保留编辑,请使用systemd override通过在/ etc / systemd / system / mysqld.service.d中创建其他conf文件。

2
我的 Kubuntu 安装中没有这样的文件夹。在“/usr/lib/systemd/”中没有“system”文件夹。 - makkasi
1
我执行了以下步骤:
  1. 输入命令 "sudo nano /lib/systemd/system/mysql.service"
  2. 输入命令 "sudo systemctl daemon-reload"
  3. 输入命令 "sudo service mysql restart"
然后它就起作用了。我也完成了第一步。祝好!
- makkasi

13

我不建议编辑原始的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更新后得以保留。


同意,我会编辑我的答案,因为这正是我最终所做的。感谢您抽出时间指出这一点。 - MNB
对于Ubuntu 16.04,应该执行mkdir /etc/systemd/system/mysql.service.dsystemctl restart mysql - rob006

0

对于我来说(在Debian Buster上的mariadb 1:10.3.23-0+deb10u1),导致Changed limits警告的原因并不是操作系统限制(似乎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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接