在工作中使用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