1

Good afternoon.

My Debian 9 server ran into an issue that rendered the OS inaccessible , I managed to extract all the raw database files (/var/lib/mysql) for my project but unfortunately the engine type was set to InnoDB.

Is there any chance I can somehow recover the database? Thanks.

Kjell
  • 75
  • 1
  • 5

1 Answers1

2

If you have the entire /var/lib/mysql then you should probably try completely replacing the current contents of /var/lib/mysql with the content you have.

Depending on your mariadb/mysql options some or all of the innodb data is global and stored in the /var/lib/mysql/ibdata1, and /var/lib/mysql/ib_logfile files. So just restoring the /var/lib/mysql/databasename/table* will usually not be enough to restore innodb data.

You could temporarily move the current current contents of that directory to another location if you already have restored or started using that. Or even better temporarily start up a new machine in a VM or something where you can test restoring the entire /var/lib/mysql directory without interrupting anything.

After placing your old data in /var/lib/mysql you should be able to start the server and hopefully extract your data. You may need to start mariadb with the options to bypass privileges depending on how locked down your privileges were. I wouldn't continue to use that though, instead I would suggest at that point you use mysqldump or your favorite tools to dump the database, then re-import it into your production database.

As you move things back and for make sure that the mysql/mariadb service account (normally mysql/mysql) owns and has read-write access to all the files.

Zoredache
  • 128,755
  • 40
  • 271
  • 413
  • Thank you for the information. What would be the correct approach of dropping the old /var/lib/mysql content into a new MariaDB installation, ie by adding the files before the MariaDB package is installed or by stopping the server and replacing the existing files? – Kjell Sep 03 '18 at 11:52
  • 1
    I would probably install mariadb, stop the daemon, then move files around. – Zoredache Sep 03 '18 at 22:56