I am having Ubuntu 14.04 desktop in which i develop software. Due to some reasons my hard disk has developed many bad sectors. I want to move my mysql server software and all the databases to a new machine. How should i do it? Somebody please help me.

  • You can use mysqldump. – taliezin Mar 31 '15 at 8:09
  • I wish to move the mysql software along with the settings so that i dont have to configure it in my new machine again. – raghavanm Mar 31 '15 at 8:10
  • There are not so many config files, check your current setup for example I think in Ubuntu /etc/mysql/my.cnf or whatever your current mysql uses. If on your new server you use the same Ubuntu, mysql version should be the same – taliezin Mar 31 '15 at 8:13
  • You can use mysqldump or if it will fail - use binary logs to restore from them – Alexey Vesnin Mar 31 '15 at 9:55
  • I have done this using mysqldump. Other things to remember on the new install is to implement any changes to my.cnf (usually in /etc/mysql) such as a different logfile size (I needed this to work with BLObs). There may be other changes if you were not using the default datadir. – MichaelJohn Jul 9 '15 at 16:01

Easiest way is probably to install Ubuntu 14.04 on the new system including mysql-server packages you already have installed on the old system; use dpkg -l mysql\* to show what those packages are (make your terminal wide enough first to not truncate columns). Ensure the new system has the same or newer versions (not older versions).

Now stop mysql on old and new systems. You can now copy over the /var/lib/mysql directory including contents; I usually use rsync for that:

# rsync -ai /var/lib/mysql/ newsystem:/var/lib/mysql/

You can also use tar to collect all the files first and copy the tarfile, as getting rsync to work with root might be a bit of a challenge:

# cd /var/lib; tar cvf /var/tmp/mysql-files.tar mysql/
# scp /var/tmp/mysql-files.tar newsystem:/var/tmp

On new system:

# cd /var/lib; mv mysql mysql.orig
# tar xvf /var/tmp/mysql-files.tar

You may want to copy /etc/mysql/ including contents in the same way.

Now start mysql again and everything should work.

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.