Migrate MySQL to another server


  • You want to migrate a full MySQL database to another server


  • Debian/Ubuntu/Raspbian
  • Installed MySQL instance on both servers (sudo apt-get install mysql-server)
  • Root password



The basic call to backup a MySQL looks like this:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

In our case:

mysqldump -u root -pSTRONGROOTPASSWORD ––all-databases > backup.sql

(no space between -p and the password!)


scp backup.sql user@host:/home/user


The basic call to import looks like this:

mysql -u root -p[root_password] [database_name] < backup.sql

In our case:

mysql -u root -pSTRONGROOTPASSWORD < backup.sql

Set debian system maintainer password

For the default installation of a MySQL on Debian, Ubuntu or Raspian, a system maintainer password is set by the package. It’s a different one for every instance. By importing the old database, the password for the new instance were overwritten. This is bad, because the MySQL will not start after reboot and other stupid things happen. So you have to restore the correct password. This is stored in /etc/mysql/debian.cnf. To get it do the following:

sudo cat /etc/mysql/debian.cnf | grep password
password = asdfadsfsdafadsgfadf
password = asdfadsfsdafadsgfadf

Setting the password:


SET PASSWORD FOR ‘debian-sys-maint’@’localhost’ = PASSWORD(‘asdfadsfsdafadsgfadf’);

flush privileges;





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s