How to restore mysql databases using raw files?

My server was recently hacked (damn it!), I tried to restore mysql dbs using my regular backup procedure to find out that mysql-dump backup was not working properly => unique solution remaining, restore mysql db from raw files (located into /var/lib/mysql).

Copying & pasting /var/lib/mysql folder did not make it, neither a copy & paste of only my own db folders. What I had to do was the following:

  1. reinstall mysql as usual (apt-get install mysql) and changing root password (along with password for all user-apps as well) <= the server was hacked!
    note: update your app code to reflect new db credentials
  2. log into mysql and recreate through sql queries all my dbs (create database <db_name>;)
  3. create app-users as well
  4. exit mysql
  5. copy your raw db folders and replace those that mysql has just created
  6. restart mysql daemon (/etc/init.d/mysql restart)

That should work.

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...