nativeInstalleroxid

Recover a MariaDB database

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

NOTE: The Approach A sections referred to below do not apply to Bitnami native installers. Users of Bitnami native installers should refer only to the Approach B sections.


NOTE: We are in the process of modifying the configuration for many Bitnami stacks. On account of these changes, the file paths and commands stated in this guide may change depending on whether your Bitnami stack uses MySQL or MariaDB.

Linux and macOS native installer users can identify which database server is used in the stack by running the command below:

 $ test -d installdir/mariadb && echo "MariaDB" || echo "MySQL"

Windows native installer users can identify which database server is used in the stack by checking for the presence of the installdir/mariadb directory. If present, the installer uses MariaDB and if not, it uses MySQL.

Depending on which database server (MySQL or MariaDB) is used by the installation, use the appropriate guides in our documentation for database-related operations.

Check logs

Before trying to recover a MariaDB database, you should check the exact error in the log file. To check the latest entries in the MariaDB log file, run the command below:

  • For Bitnami installations following Approach A (using Linux system packages):

      $ sudo tail -n 100 installdir/mariadb/logs/mysqld.log
    
  • For Bitnami installations following Approach B (self-contained installations):

      $ sudo tail -n 100 installdir/mariadb/data/mysqld.log
    

Restart and repair the database

Assume the following error in the log file:

110108 10:37:45 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'user' is marked as crashed
  • The MariaDB database is configured to use InnoDB engine by default. You can add the innodb_force_recovery=1 option in the main MariaDB configuration file at installdir/mariadb/my.cnf to try and fix the database:

      [mysqld]
      innodb_force_recovery = 1
    
  • Start the MariaDB database with the following command:

      $ mysqld --skip-grant-tables --user=mysql --skip-external-locking --port=3306 --sock=installdir/mariadb/tmp/mysql.sock
    
  • Open a new console and try to log in to the database:

      $ mysql -u root -p
    
  • In this case, the error was related to the mysql.user table. Run these commands:

      MariaDB> use mysql;
      MariaDB> repair table user;
      MariaDB> check table user;
      MariaDB> exit;
    

If the table is recovered, you should see “OK” in the mysql.user status table. Do not forget to remove the innodb_force_recovery option from the my.cnf file and restart the MariaDB server again.

$ sudo installdir/ctlscript.sh restart mariadb

If you find a different error or cannot fix an issue, we can try to help at http://community.bitnami.com.

Last modification July 26, 2021