Recover a MySQL database
NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:
$ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."
The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.
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. To identify which database server is used in your stack, run the command below:
$ test -d /opt/bitnami/mariadb && echo "MariaDB" || echo "MySQL"
The output of the command indicates which database server (MySQL or MariaDB) is used by the installation, and will allow you to identify which guides to follow in our documentation for common database-related operations.
Before trying to recover a MySQL database, you should check the exact error in the log file. To check the latest entries in the MySQL log file, run the command below:
For Bitnami installations following Approach A (using Linux system packages):
$ sudo tail -n 100 /opt/bitnami/mysql/logs/mysqld.log
For Bitnami installations following Approach B (self-contained installations):
$ sudo tail -n 100 /opt/bitnami/mysql/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 MySQL database is configured to use InnoDB engine by default. You can add the innodb_force_recovery=1 option in the main MySQL configuration file at /opt/bitnami/mysql/etc/my.cnf to try and fix the database:
[mysqld] innodb_force_recovery = 1
Start the MySQL database with the following command:
$ mysqld --skip-grant-tables --user=mysql --skip-external-locking --port=3306 --sock=/opt/bitnami/mysql/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:
mysql> use mysql; mysql> repair table user; mysql> check table user; mysql> 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 MySQL server again.
$ sudo service bitnami restart mysql
If you find a different error or cannot fix an issue, we can try to help at http://community.bitnami.com.