• MySQL – exporting and importing databases

    Once a database has been created it can be very useful to be able to export the data and then import it on another Slice or server.

    This procedure is very simple and can greatly ease any migration of data.

    Let’s get stuck right in and look at exporting the database.

    Export

    In this example, we will export the ‘mytestdb’ database into a file called ‘mytestdb.sql’:

    mysqldump -u root -p mytestdb > mytestdb.sql

    Once done, the sql file can be copied to a new Slice or server ready to be imported into MySQL.

    Import

    Importing the data is just as easy but involves two steps.

    The first step is to create a blank database ready to receive the data (remember this is on the Slice or server to which the database is going to imported):

    mysqladmin -u root -p create mytestdb2

    Once done, all that is left is to actually import the data:

    mysql -u root -p mytestdb2 < mytestdb.sql

    Done. It really is as simple as that.

    Categories: Mysql

    Comments are currently closed.