Modifying a systemd startup file for Mariadb

Ubuntu Support Template

Ubuntu Version:
24.04

Desktop Environment (if applicable):
Gnome, CLI

Problem Description:
I had a system crash due to power issues. I can’t boot my system. It goes to an “emergency CLI” which doesn’t work. I happened to have a backup system in which I messed up the Gnome when using the classic interface. I can read the damaged hard drive even though I can’t boot.

I have been trying to restore some Mariadb databases. I am using InnoDB and need to add “–innodb-force-recovery=1” to my systemd system file. I have done some Internet searches to try and understand how to do this but there is not enough information. I have a vague idea of what to do. I need to add a .conf file to /etc/systemd/system/mariadb.service.d . My problem is what goes in that .conf file to provide the command line option I need.

Before Posting:
:mag: Please check if similar issues have already been reported and resolved.

You should not modify the main systemd unit file directly. Instead, create an override file.

Run (from a working system or mounted disk):

sudo mkdir -p /etc/systemd/system/mariadb.service.d
sudo nano /etc/systemd/system/mariadb.service.d/recovery.conf

Add the following:

[Service]
ExecStart=
ExecStart=/usr/sbin/mariadbd --innodb-force-recovery=1

Important:
The empty ExecStart= line clears the original definition before redefining it.

Then reload systemd:

sudo systemctl daemon-reload

And start MariaDB:

sudo systemctl start mariadb

:warning: Use --innodb-force-recovery only temporarily to dump your databases. Remove the override file afterward and reload systemd again.

1 Like

Or

sudo systemctl edit mariadb.service

Which will allow you to make the override and makes the directory for you with correct permissions

1 Like

You don’t add --innodb-force-recovery directly to the systemd unit. The clean way on Ubuntu 24.04 is to set it in MariaDB’s config, not by modifying mariadb.service.

Create a drop-in config file like this:

sudo nano /etc/mysql/mariadb.conf.d/99-recovery.cnf

Add:

[mysqld]
innodb_force_recovery=1

Save it, then reload and start:

sudo systemctl daemon-reload
sudo systemctl start mariadb

You don’t need to touch /etc/systemd/system/mariadb.service.d unless you’re overriding the ExecStart command (not recommended here). MariaDB reads options from the .cnf files automatically.

Important: start with 1 only. If it doesn’t start, increase gradually (2 → 3 → 4, etc.). The higher the value, the more features are disabled, and at 4+ you risk data loss on writes. This mode is only for dumping data — don’t run production like this.

Once it starts, immediately dump your databases:

mysqldump -u root -p --all-databases > recovery.sql

After dumping, remove the 99-recovery.cnf file and restart MariaDB normally.

If InnoDB still refuses to start even with force recovery, the tablespace may be heavily corrupted. In that case, you’d need to attempt file-level recovery from /var/lib/mysql, and if native recovery fails, try some third party tools like Stellar Repair for MySQL can sometimes extract data directly from damaged InnoDB files when the server cannot fully initialize.

But first try the proper .cnf method — that’s the correct approach on Ubuntu.