Laravel Published

MySQL/MariaDB driver vs laravel-backup

MariaDB 11 removed the mysqldump binary, which can break backups for projects still using the MySQL driver. Switching drivers isn’t always straightforward due to differences like UUID storage. This post shows a simple workaround to fix backups without changing your database schema.

Backups stopped working

Recently I ran into an issue with the laravel-backup not working anymore. After some investigation, I found out that the issue was caused by the fact that MariaDB 11 removed the mysqldump binary, which is used by the MySQL driver in laravel-backup. This caused my backups to fail, as the laravel-backup package looks at the configured driver of the project to determine which dump binary it should use.

After some research I found that, since MariaDB 11.0, the legacy mysqldump binary (or symlink) has been removed and replaced with mariadb-dump. This caused the backups to fail, as the laravel-backup package looks at the configured driver of the project to determine which dump binary it should use.

My first instinct was to just switch to the MariaDB driver. During testing I noticed quickly that that switch would introduce several issues. For example, as the app was using the MySQL driver, which stores UUIDs as char(36). With the MariaDB driver, it stores it as the UUID type. That results in future migrations using a different type for id columns, which would cause foreign key issues as the columns are not the same type. Switching drivers would therefore require a full schema migration, including foreign keys. That was not a task I wanted to take on currently, just to restore backup functionality.

Restoring the backup functionality

The first thing that came into my mind was if I could just create a symlink to the mariadb-dump binary with the name mysqldump. However, the hosting environment of this project kept me from doing that.

The next step was to see if the laravel-backup package has the possibility to change the dump binary. There’s no built-in option to change the dump binary directly. However, the backup package uses the db-dumper package. I found out that allows you to extend the dumper per driver. This makes it possible to keep using the MySQL driver while swapping out the underlying dump tool, which leads me to overriding the MySQL dumper with the MariaDB dumper:

// The database is configured as MySQL, but mysqldump is unavailable.
// Override the MySQL dumper to use mariadb-dump instead.
DbDumperFactory::extend('mysql', static fn () => new MariaDb());

This approach restores backup functionality without requiring any changes to the database schema.

Keep reading

Related posts