MySQL max_open_files超过1024


11

启动MariaDB时,我得到了[警告]无法将max_open_files的数量增加到1024以上(请求:4607)

$ sudo systemctl status mysqld
● mysqld.service - MariaDB database server
  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
  Active: activating (start-post) since Tue 2014-08-26 14:12:01 EST; 2s ago
Main PID: 8790 (mysqld);         : 8791 (mysqld-post)
  CGroup: /system.slice/mysqld.service
      ├─8790 /usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid
      └─control
    ├─8791 /bin/sh /usr/bin/mysqld-post
    └─8841 sleep 1

Aug 26 14:12:01 acpfg mysqld[8790]: 140826 14:12:01 [Warning] Could not increase number of max_open_files to more than 1024 (request: 4607)

我尝试解决此文件中max_open_files的问题未成功:

$ sudo nano /etc/security/limits.conf 
mysql           hard    nofile          8192
mysql           soft    nofile          1200

我什至再次重新启动了计算机,但是遇到了同样的问题。

/etc/mysql/my.cnf如下所示:

[mysql]

# CLIENT #
port                           = 3306
socket                         = /home/u/tmp/mysql/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /home/u/tmp/mysql/mysql.sock
pid-file                       = /home/u/tmp/mysql/mysql.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000
skip-name-resolve
sql-mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now                 = 1
innodb                         = FORCE
innodb-strict-mode             = 1

# DATA STORAGE #
datadir                        = /home/u/tmp/mysql/

# BINARY LOGGING #
log-bin                        = /home/u/tmp/mysql/mysql-bin
expire-logs-days               = 14
sync-binlog                    = 1

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 500
thread-cache-size              = 50
open-files-limit               = 65535
table-definition-cache         = 1024
table-open-cache               = 2048

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 128M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 2G

# LOGGING #
log-error                      = /home/u/tmp/mysql/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 1
slow-query-log-file            = /home/u/tmp/mysql/mysql-slow.log

max_open_files如何解决该问题?


自更改限制以来,您是否已重新启动mySql?这些事情通常不会简单地引起文件更改,通常必须重新启动该过程以获取更改。您也可以使用ulimit命令验证限制。更改后您重新启动了吗?
mdpc

更改限制后,我重新启动了计算机。查看ulimit输出,我的更改没有解决:$ ulimit unlimited $ ulimit -Sa | grep“打开文件”打开文件(-n)1024 $ ulimit -Ha | grep“打开文件”打开文件(-n)4096。什么会出错?
user977828 2014年

Answers:


17

编辑/etc/security/limits.conf并添加以下行

mysql soft nofile 65535
mysql hard nofile 65535

然后重启。

然后编辑/usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/mariadb.service添加

LimitNOFILE=infinity
LimitMEMLOCK=infinity

然后重新启动数据库服务:

systemctl reload mariadb.service

1
请注意,至少在systemd版本209上,无穷大表示65535。如果您想要的不止于此,请输入数字,而不是无穷大。
思万2015年

3
至少对于RHEL 7中的Mariadb 5.5,该文件(/usr/lib/systemd/system/mariadb.service)中的注释警告您不要编辑该文件本身,而是创建一个包含文件的service.d目录。像:/etc/systemd/system/mariadb.service.d/foo.conf。确保在该文件的顶部,在这两个限制行之前添加“ [Service]”。任何更改后,它也建议“ systemctl --system守护程序重新加载”。这些细节使我发疯了一个多小时!
IcarusNM 2015年

这在具有MySQL 5.7的Ubuntu 14.04中不起作用。服务文件不存在,并且未安装systemctl软件包。
Ty。

检查/etc/systemd/system/mysql.service.d/limits.conf/etc/systemd/system/mariadb.service.d/limits.conf 它完美地为我工作
卢卡

2

另一个原因是:
您必须注意table_open_cach

mysql中的代码 mysqld.cc

wanted_files= 10 + max_connections + table_cache_size * 2;

尝试较低的table_open_cach价值


1

您可以在mariadb.service文件中查看官方说明。

[root@mariadb5.5 /]# cat /usr/lib/systemd/system/mariadb.service | grep exam -A 5
# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#       [Service]
#       LimitNOFILE=10000

它需要重新启动操作系统。虽然我认为这应该写在官方手册中 ...


1
我不需要在Fedora 28上重启。它只要求我systemctl daemon-reload在重新启动MariaDB时运行。
DanMan '18

0

我在Ubuntu 15.10mysql上也遇到了同样的问题,并使用先前的答案对其进行了修复,但有一些细微的差异。

我首先/etc/security/limits.conf如上所述进行了更改。

我加了(仅此而已)

LimitNOFILE=infinity

/lib/systemd/system/mysql.service(很小的位置差异)

然后做了

systemctl daemon-reload
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.