Increase open-files-limit in MariaDB on CentOS 7 with systemd

Tired of the privacy invasion of browsers? Worried about the risk of seeing ads everywhere? Give the Brave Browser a try. All Chrome extensions are compatible. None of the telemetry. Auto-blocks ads and still support content creators like me.

Download the Brave browser now »

Profile image of Mattias Geniar

Mattias Geniar, April 29, 2015

Follow me on Twitter as @mattiasgeniar

Gone are the days where simply changing /etc/my.cnf would be sufficient. Enter the new systemd world.

systemd itself has a limit that controls how many files a service can open, regardless if what you configure in /etc/my.cnf or /etc/security/limits.conf.

To increase the open files limit in MariaDB running on a RHEL or CentOS 7 with systemd, do the following.

First, create a new directory that will hold the MariaDB service changes in systemd. By making your changes here, you’ll make sure that package upgrades that would/could overwrite the mariadb.service file don’t remove your own changes.

$ mkdir -p /etc/systemd/system/mariadb.service.d/

Next, configure systemd so that the MariaDB service can open more files.

$ cat /etc/systemd/system/mariadb.service.d/limits.conf
[Service]
LimitNOFILE=10000

In order for systemd to be aware of those changes, you have to reload the systemd daemon. This only reloads the configs that systemd knows about, it does not restart any actual service.

$ systemctl daemon-reload

The above tells systemd that MariaDB can open 10000 files of it wants. Restart the MariaDB service now to make those changes stick.

$ systemctl restart mariadb

And you’re done.

Increase the value in /etc/systemd/system/mariadb.service.d/limits.conf if needed.

These changes are also “documented” in the mariadb.service service file in systemd.

$ 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

Just another thing to keep in mind.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.