I installed MariaDB and failed to notice it replaces Mysql. During the install, it moved the Mysql data directory to mysql-5.7. I removed MariaDB and reinstalled Mysql and tried to restore my databases by simply moving them from mysql-5.7 to mysql and restarting Mysql. Mysql won't start again and therefore I cannot use mysqldump as suggested here - How to restore mysql databases after upgrading to mariadb. How can I restore my databases?

For reference, I am running Ubuntu Server 16.04 and Mysql 5.7.

  • What do you mean by it moved data directory to mysql-5.7? – George Udosen Aug 1 '17 at 6:06
  • While installing MariaDB, it stated The old data directory will be saved at new location. A file named /var/lib/mysql/debian-*.flag exists on this system. The number indicated a database binary format version that cannot automatically be upgraded (or downgraded). Therefore the previous data directory will be renamed to /var/lib/mysql-* and a new data directory will be initialized at /var/lib/mysql. Since the only folders in /var/lib that match that are mysql-files and mysql-5.7 and mysql-files is empty, I assume the mysql folder was moved to mysql-5.7. – Pockets Aug 1 '17 at 6:19

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

  • saved my life ;) – newah May 17 at 14:05

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.

  • 1
    this does not work and causes the system failing to start – user1034912 Oct 6 '18 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.