Accidentally installed MariaDB over Mysql. How do I recover my Mysql databases?

I figured this out:

  1. Copy the renamed folder (/var/lib/mysql_5.7) to a safe location. (If you preserve ownership & permissions you can probably skip fixing them in step 4.)

  2. Uninstall MySQL and remove all mysql related folders from /var/lib/.

  3. Reinstall MySQL.

  4. Check permissions on the new /var/lib/mysql/ files & folders. If your backed up files don't match, fix them to match. (Mine was

    chown -R mysql:mysql location_to_backed_up_folder/

    chmod 750 location_to_backed_up_folder/mysql/ location_to_backed_up_folder/any_other_folders/

    chmod 640 location_to_backed_up_folder/all_other_files

  5. Stop mysql

  6. Rename the backed up folder to "mysql"

  7. Copy the backed up folder & files (preserving ownership & permissions) to /var/lib/

    cp -aR location_of_backed_up_folder/ /var/lib/

  8. Restart mysql


You can continue using Maria Db if you have a copy of mysql-5.7 (in /var/lib while maria db got installed) to some temporary location.

Now, in your /var/lib, you will have a folder called mysql which is your current db (without your old dump).

Now, stop your mysql. Move the mysql folder in /var/lib to some location for safety purpose and move the mysql-5.7 folder to /var/lib and rename it as mysql. Set the same privileges as set for previous mysql folder.

Restart mysql service again. You will have the old dump now.