Re: Retrieve MySQL database from old hard drive

To mount your old hard drive in your new computer:

Open the old computer and take out the hard drive. Open your new computer and connect the hard drive to the drive data ribbon. If you are uncomfortable with that, you can buy a “rack” which plugs into a USB port on the new computer and which allows you to insert the naked internal drive into the rack. I think there are also things called USB enclosures which do the same thing. Sorry though – I don't know that much about the hardware end of things.

Boot up the new computer and Ubuntu should hopefully recognize the new drive (most of the time there is no problem).

A second drive will be given a device name like /dev/sdb. The first partition would be called /dev/sdb1. To mount the first partition:

Code:

sudo mkdir /media/sdb1
sudo mount /dev/sdb1 /media/sdb1

To recover your database:

First install mysql on the new machine. 

Code:

sudo apt-get install mysql-server-5.0

If your old database was called 'mydata', then you might want to create an empty database on your new machine also called 'mydata'. This will create the appropriate folder. I'm not sure this is really necessary however.

Your old computer's first partition would then be mounted at /media/sdb1. The mysql database (if it is on the first partition) would be located at /media/sdb1/var/lib/mysql. 

First stop the mysql server:

Code:

sudo /etc/init.d/mysql stop

Now simply the copy the entire mysql director 

/media/sdb1/var/lib/mysql

to 

/var/lib/mysql/

Check that the files are owned by mysql, part of the mysql group, and have owner and group read/write permissions. 

sudo chown -R mysql:mysql /var/lib/mysql

Then restart the mysql server:

Code:

sudo /etc/init.d/mysql start

You should then be able to access your database again.