MySQL - exporting and importing records

Whether it is for a quick database backup or to import existing records to a new database for a server move, importing and exporting records is a basic and essential function.

Luckily, saving the data and moving it to a new MySQL database could not be easier.

Firstly, log into your VPS. The commands shown below are made from the BASH command prompt - in other words, you do not need to log into MySQL.

Export

So, to export a particular database issue one simple command:

mysqldump -u root -p pickled1 > pickled1.sql

It's as simple as that. In this example, I used the MySQL root user and 'pickled1' refers to the database we have been using during these articles.

Once done, we have a file named 'pickled1.sql' which can be copied to the new server ready for importing to the new MySQL install.

Import

Importing the data is just as simple.

Create the new database (it does not have to be named the same as the old database):

mysqladmin -u root -p create pickled1_new

Now import the data from the old database to the newly created one:

mysql -u root -p pickled1_new < pickled1.sql

Again, that's it. Very simple indeed.

Now the newly created 'pickled1_new' database has been populated with the data exported from the original 'pickled1' database.

PickledOnion

Digg it | del.icio.us | reddit | StumbleUpon

Comments are closed for this article.