When working with MariaDB on systemd-based systems, you'd expect to find the service unit file at /etc/systemd/system/multi-user.target.wants/mysql.service
, but sometimes it's just not there. Let me walk you through how to properly locate and modify the service file.
Systemd service files can exist in several locations with different priorities:
/usr/lib/systemd/system/
- Default installed unit files (package manager)/etc/systemd/system/
- System administrator modifications/run/systemd/system/
- Runtime modifications
Use systemctl
to reveal the true location:
systemctl status mysql.service | grep Loaded
# Example output:
# Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
For MariaDB specifically, try:
sudo find / -name "*mariadb*.service" 2>/dev/null
# Common locations:
# /usr/lib/systemd/system/mariadb.service
# /etc/systemd/system/mariadb.service.d/override.conf
Instead of editing the original file, create an override:
sudo systemctl edit mysql.service
# This creates:
# /etc/systemd/system/mysql.service.d/override.conf
Example override to change memory limits:
[Service]
LimitNOFILE=65536
LimitMEMLOCK=infinity
Always remember to reload systemd after making changes:
sudo systemctl daemon-reload
sudo systemctl restart mysql
Verify your changes took effect:
systemctl show mysql.service --property LimitNOFILE
systemctl show mysql.service --property LimitMEMLOCK
When working with MariaDB (MySQL's popular drop-in replacement) on systemd-based Linux distributions, you might need to modify the service configuration but find the file isn't where expected. Let's explore how to properly locate and manage these service files.
systemd service files typically exist in these directories (ordered by precedence):
/etc/systemd/system/ # Local administrator configurations
/run/systemd/system/ # Runtime configurations
/usr/lib/systemd/system/ # Default vendor configurations
Use these commands to locate the MariaDB/MySQL service file:
# Method 1: Using systemctl
systemctl status mysql | grep "Loaded"
# Sample output: Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
# Method 2: Using find command
sudo find / -name "*mysql*.service" -o -name "*mariadb*.service" 2>/dev/null
# Method 3: Check package installation
rpm -ql mariadb-server | grep service # For RPM-based systems
dpkg -L mariadb-server | grep service # For Debian-based systems
Never edit the original service file in /usr/lib/systemd/system/. Instead, create an override:
# Create override directory if it doesn't exist
sudo mkdir -p /etc/systemd/system/mysql.service.d/
# Create custom configuration
sudo nano /etc/systemd/system/mysql.service.d/override.conf
# Add your customizations, for example:
[Service]
LimitNOFILE=infinity
RestartSec=5s
# Reload systemd configuration
sudo systemctl daemon-reload
sudo systemctl restart mysql
Here are some frequent modifications developers make:
# To change startup timeout (common for large databases)
[Service]
TimeoutStartSec=300
# To add environment variables
[Service]
Environment="MYSQLD_OPTS=--skip-name-resolve"
# To modify resource limits
[Service]
LimitNOFILE=65535
LimitMEMLOCK=infinity
If you're still having issues:
- Check if you're using mariadb.service instead of mysql.service
- Verify package installation with
systemctl list-unit-files | grep -i mysql
- For Docker containers, check the entrypoint scripts instead