在工作中使用mysql数据库的时候或许会遇到下面这个错误:
[ERROR] when opening file: '/var/tmp/#sql_2ad6_1.MAD' (Errcode: 24)
这是因为Mariadb(MySQL)打开的文件描述符个数超出了open_files_limit的限制,这时我们需要先检查一下数据库当前open_files_limit的值:
mysql> show global variables like 'open_files_limit'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | open_files_limit | 1024 | +------------------+-------+ 1 row in set (0.00 sec)
为了解决这个问题,就需要将open_files_limit重新设置比较大一点,怎么做呢?很简单
首先我们先看一下Mariadb的设置说明:
#cat /usr/lib/systemd/system/mariadb.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
# .include /lib/systemd/system/mariadb.service
# ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# 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
# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload
这样就很简单了吧。。。。。
首先创建一个目录
#mkdir -p /etc/systemd/system/mariadb.service.d/
在该目录下创建一个limits.conf,添加如下内容
[Service] LimitNOFILE=10240
接着重新加载一下
#systemctl daemon-reload
最后重新启动一下Mariadb(mysql)服务
#systemctl restart mariadb
接着在来查看一下设置后的open_files_limit的值:
mysql> show global variables like 'open_files_limit'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | open_files_limit | 10240 | +------------------+-------+ 1 row in set (0.08 sec)
这样就OK了。
或者来一个最直接暴力的:
直接在/usr/lib/systemd/system/mariadb.service中添加LimitNOFILE=10240
如下:
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
LimitNOFILE=10240
接着重新加载一下
#systemctl daemon-reload
最后同样重启一下Mariadb(mysql)服务
#systemctl restart mariadb