My motherboard suddenly died, but it was an old machine(running natty). So I put together a new Ubuntu system with a clean 14.04 install (same username) and mounted the old drive (with the full filesystem) as secondary device.

How can I migrate mysql setup and data, and apache setup and data from the old drive to the new machine?

Any assistance will be much appreciated.


The Ubuntu 11 to 14.04 upgrade means your kernel libraries, and therefore, binaries will have to be different, including Apache and MySQL server. So, you have to install the binaries again and you can only copy text configuration files and hope that the configuration parameters still work.

For Apache, install Apache first, then:

stop apache

Copy all of the text files under the /etc/apache2 directory on the old drive to /etc/apache2 on the new drive, preserving relative paths and replacing all duplicates:

cp -r /path/to/old/etc/apache2 /etc/apache2

Manually set the symbolic links between mods-available and mods-enabled in the new /etc/apache2 to match those under the old /etc/apache2. If there are modules that are renamed or use different settings and Apache complains, edit your apache2.conf, as needed. Then,

start apache

For MySQL, install MySQL server first. @vembutech's answer is good, but he left out that if you had any custom MySQL settings, e.g. for memory, thread allocation, and so forth, you do not have them in the new MySQL install. So: ` Save a copy of the new /etc/mysql/my.cnf:

sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.orig

Copy /etc/mysql/my.cnf from the old disk to /etc/mysql/my.cnf on the new disk:

sudo cp /path/to/old/etc/mysql/my.cnf /etc/mysql/my.cnf

Missing parameters needed by the newer MySQL can be gotten from the saved copy of my.cnf.

  • Thanks for the info. What about the databases themselves? Can they be migrated by copying files from the old drive to the new one? – newbie Sep 24 '14 at 21:26
  • 1
    The short answer yes, I've been able to do that successfully in the past. The longer answer is it depends on your software versions, selinux contexts, stored procedure compatibility, and so forth. So, it is not a slam dunk that it will work every time. Those files are under /var/lib/mysql directory. Rename the new install /var/lib/mysql directory to move it out of the way and keep it around so you can recover it if you need to. Then, create a symbolic link in new disk /var/lib/mysql pointing to the old disk /var/lib/mysql (or just copy old /var/lib/mysql to the new disk /var/lib/mysql). – Andrew Sep 25 '14 at 18:07

If you are having the data folder of MySQL where ibdata and cnf/.ini file available. You can rebuild the MySQL instance by following the below steps.

  • Install MySQL in new instance with same MySQL version as before
  • stop mysql
  • Open cnf file and change the datadir attribute the old MySQL ibdata file available location.
  • delete log files in the data folder created by older instance and start MySQL.

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.