Solving development problems  |  About this blog

Archive for the ‘tar’ tag

MySql dump, tar, restore…

Very often you need to migrate your MySQL database from one server to another, from Windows to Linux, Linux to Linux….

So, first you need to create dump of your existing database, to export it to a file. Here is the command:

mysqldump -P 3306 -u database_username -p database_name > /home/somedirectory/your_database.sql

-P - means port, if you don’y mention it default port is used (usually 3306)
-u – means database username
-p – means password but we didn’t specified it so after this command is executed we will be asked to type a password
database_name
– is the name of your database you want to export
> location – at the end you specify directory where you want to create this dump

You probably want to zip this and you can use TAR (install Cygwin if working on Windows):
Here is the command:

tar cvf database.tar /home/somedirectory/your_database.sql

Transfer this file on other server using FTP… And unzip it if you want using command:

tar -xvf database.tar

Then import the database:

mysql -P 3306 -u  database_username -p new_existing_database_name < /home/somedirectory/public_ftp/your_database.sql

-P - means port, if you don’y mention it default port is used (usually 3306)
-u – means database username
-p – means password but we didn’t specified it so after this command is executed we will be asked to type a password
new_existing_database_name
– is the name of your existing database on new server where you want to import data
< location – at the end you specify from which directory you want to import database

And thats it…

Written by Avivo

February 25th, 2009 at 10:27 am