scripts lineage2  :::  Server Packs lineage 2 — best scripts for admin servers   :::  Projects lineage Turnkey
l2-scripts.com  Freelance Studio

ArticlesTechnical guides9 min read

How to rescue a MySQL or MariaDB database when the server will not start

The MySQL or MariaDB service crashes on startup and there is no fresh dump? Here is what to do step by step: save the files, start the server in recovery mode, take a dump and move the data to a clean installation.

The golden ruleDo not delete or reinstall anything until you have a full copy of the data directory. One careless command on a damaged database can make the loss permanent.

Step 1. Find the cause

Before you try to repair the database, read the error log: quite often the server fails to start for reasons that have nothing to do with damaged data.

# Linux
sudo journalctl -u mariadb -n 100 --no-pager   # for MySQL: -u mysql
sudo tail -n 100 /var/log/mysql/error.log
df -h                                          # is the disk full?

On Windows the error log is a file with the .err extension in the data directory (usually named after the computer). Service messages also appear in Event Viewer under Windows Logs, Application.

Causes you can fix without any recovery:

  • the disk is full;
  • a mistake in my.cnf or my.ini after editing;
  • port 3306 is taken by another server instance or another program;
  • wrong permissions on the data directory (on Linux it must belong to the mysql user).

If the log reports InnoDB corruption (Database page corruption, Assertion failure, page read errors), go on to the next steps.

Step 2. Copy the whole data directory

The database server must be stopped: a file copy of a running server is inconsistent. Copy the whole data directory, not just the folder of your server database: InnoDB tables also need the shared ibdata1 file, the ib_logfile* logs (the #innodb_redo directory in MySQL 8), the undo files and, in MySQL 8, the mysql.ibd data dictionary.

SystemDefault data directory
Debian, Ubuntu (MariaDB and MySQL)/var/lib/mysql
Windows, MySQL 8C:\ProgramData\MySQL\MySQL Server 8.0\Data
Windows, MariaDBC:\Program Files\MariaDB 10.11\data (use your version number)
Windows XP, MySQL 5.1 (old installations)C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data

The exact path is set by the datadir option in the config. The ProgramData folder is hidden on Windows: turn on hidden items in the File Explorer View menu or simply paste the path into the address bar. If the disk is full, copy to another disk or straight to another machine.

# Linux
sudo systemctl stop mariadb          # or mysql
sudo cp -a /var/lib/mysql /root/mysql-data-$(date +%F)
# or straight into an archive:
sudo tar -czf /root/mysql-data-$(date +%F).tar.gz -C /var/lib mysql
:: Windows, Command Prompt run as administrator
net stop MySQL80
robocopy "C:\ProgramData\MySQL\MySQL Server 8.0\Data" "D:\mysql-data-backup" /E

The Windows service name may differ (MySQL80, MySQL, MariaDB): check it in the Services console (services.msc).

This copy is your safety netDo all further experiments only after the copy is ready. If anything goes wrong, you can always return to the original state and try again.

Step 3. Start InnoDB in recovery mode

The innodb_force_recovery option makes InnoDB start while skipping some checks and recovery operations. The goal is not to repair the database but to get the server running just long enough to take a dump. Add the option to the [mysqld] section of the config and start the service:

[mysqld]
innodb_force_recovery = 1
LevelWhat is skippedRisk
1The server keeps running even if it finds corrupt pages and tries to skip broken records and pages when readingSafe
2InnoDB background threads (the master thread and purge) do not startSafe
3Unfinished transactions are not rolled back after a crashRelatively safe
4No insert buffer merge, no table statisticsCan permanently corrupt data files
5Undo logs are not read: unfinished transactions are treated as committedCan permanently corrupt data files
6The redo log is not applied at startupCan permanently corrupt data files
  1. Start with 1. If the server does not start, raise the value by one, restarting the service and checking the log each time.
  2. Stop at the first value that lets the server start and take a dump right away (step 4).
  3. Use values 4 to 6 only when you have the copy from step 2, and only to get the data out.
  4. While the option is on, do not start the game server or the website.
Writes are blockedIn current versions any value above 0 blocks data changes, and from 4 upwards InnoDB is read-only. That is expected: in this mode you only read and export data. Remove the option from the config as soon as the dump is done.

Step 4. Take a dump

While the server is running in recovery mode, export the server databases to an SQL file. In MariaDB the tool is called mariadb-dump (the old mysqldump name usually works too); in MySQL it is mysqldump. Use your own database name; if your pack has separate login and game server databases, list them after --databases separated by spaces.

mysqldump -u root -p --routines --events --databases l2jdb > l2jdb_dump.sql

# MariaDB:
mariadb-dump -u root -p --routines --events --databases l2jdb > l2jdb_dump.sql

Check the result: the file must not be empty, and its last line should start with -- Dump completed (run tail -n 1 l2jdb_dump.sql).

If the dump stops at a particular table, export everything else without it and try to save the problem table separately:

mysqldump -u root -p --routines --events --databases l2jdb \
  --ignore-table=l2jdb.broken_table > l2jdb_without_broken.sql

mysqldump -u root -p l2jdb broken_table > broken_table.sql

MyISAM tables (common in older packs) can often be repaired with mysqlcheck -u root -p --repair l2jdb. This command does not repair InnoDB tables: their data can only be saved with a dump.

Dumps on WindowsRun the commands in a regular Command Prompt (cmd) from the server's bin folder, for example C:\Program Files\MySQL\MySQL Server 8.0\bin, or use the full path to the program. In Windows PowerShell use the --result-file=l2jdb_dump.sql option instead of redirecting output to a file: redirection saves the file as UTF-16, and such a dump will not load later.

Step 5. Clean installation and restoring the dump

Now start the server on a clean data directory and load the dump into it. Do not delete the damaged directory, rename it: it may still come in handy.

  1. Stop the service and remove innodb_force_recovery from the config.
  2. Rename the old data directory and create a new one (see the MariaDB on Linux example below). On Windows, uninstall the server in Programs and Features, rename the old Data folder (you already have a copy) and install the server again: the installer creates a clean directory.
  3. Start the service and load the dump.
  4. Recreate the user the game server uses to connect to the database: accounts are stored in the mysql system database, which we did not transfer.
  5. Check the database in a client (Navicat, HeidiSQL or the console), then start the login and game servers.
sudo systemctl stop mariadb
sudo mv /var/lib/mysql /var/lib/mysql.broken
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql
sudo mariadb-install-db --user=mysql --datadir=/var/lib/mysql
# for MySQL 8 use this instead of the previous line:
# sudo mysqld --initialize-insecure --user=mysql
sudo systemctl start mariadb
sudo mariadb < l2jdb_dump.sql        # for MySQL: sudo mysql < l2jdb_dump.sql
CREATE USER 'l2j'@'localhost' IDENTIFIED BY 'password_from_server_config';
GRANT ALL PRIVILEGES ON l2jdb.* TO 'l2j'@'localhost';

Take the login, password and database name from your pack's database connection config. After --initialize-insecure the MySQL root password is empty, so set one right away with ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';.

Versions and the old methodA physical copy of the data directory can only be restored to the same server branch and version (MySQL to MySQL, MariaDB to MariaDB). An SQL dump is portable and can also be loaded into a newer version. The old advice to reinstall MySQL and put the database folder back into data works only for MyISAM tables and the same server version; it does not work for InnoDB.

How to avoid this in the future

  • Dump the database on a schedule, at least once a day, and keep several recent copies.
  • Do not keep copies only on the same server: move them regularly to another machine or to cloud storage (for example with rsync or scp).
  • Test restoring a dump on a test machine from time to time: an untested copy may turn out empty or broken.
  • Shut the database server down properly and never cut the power: sudden power loss is the main cause of damaged tables.
  • Keep an eye on free disk space.
  • For large MariaDB databases there is mariadb-backup, a hot backup tool that copies the files without stopping the server.

Here is an example of a daily backup on Linux. Create the script /usr/local/bin/l2-backup.sh (for MySQL replace mariadb-dump with mysqldump):

#!/bin/bash
set -euo pipefail
DIR=/var/backups/l2
mkdir -p "$DIR"
mariadb-dump --single-transaction --routines --events --databases l2jdb \
  | gzip > "$DIR/l2jdb_$(date +%F_%H-%M).sql.gz"
# delete copies older than 14 days
find "$DIR" -name 'l2jdb_*.sql.gz' -mtime +14 -delete

Make the script executable and add it to cron (sudo crontab -e):

sudo chmod +x /usr/local/bin/l2-backup.sh

# crontab line: every day at 04:30
30 4 * * * /usr/local/bin/l2-backup.sh
Password and dump consistencyIf cron runs the script as root and root logs in to MariaDB via unix_socket (the default on Debian and Ubuntu), no password is needed. Otherwise store the login and password in /root/.my.cnf (a [client] section, permissions 600) instead of putting the password on the command line. The --single-transaction option gives a consistent dump of InnoDB tables without stopping the server; if your pack has MyISAM tables, it is safer to take the dump while the game server is stopped.

On Windows the same is done with Task Scheduler: create a task that runs a PowerShell script once a day, for example (the login and password go into a my.cnf file with a [client] section):

$d = Get-Date -Format 'yyyy-MM-dd'
$dump = 'C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe'
& $dump --defaults-extra-file=C:\l2backup\my.cnf --single-transaction --routines --events --databases l2jdb "--result-file=D:\l2backup\l2jdb_$d.sql"

More server maintenance tips are in the guide Linux for game server admins.

Published 14 November 2026

Read also

Need help with your server?

We help with the server pack, setup, protection and launch — one-off or on an ongoing basis.

L2‑Scripts newsletter

Get L2‑Scripts news by email

And 5% off all studio services while you stay subscribed.

The discount is valid while you are subscribed: when ordering, tell the manager your subscription address on Telegram.