Once a database has been created it can be very useful to be able to export the data and then import it on another server.
This procedure is very simple and can greatly ease any migration of data.
Let's get right in and look at exporting the database.
In this example, we will export the 'mytestdb' database into a file called 'mytestdb.sql':
mysqldump -u root -p mytestdb > mytestdb.sql
Er, that's it.
Once done, the sql file can be copied to a new server ready to be imported into MySQL.
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 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
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

4 Comments
This seems to only backup the schema
#fail
Thanks
Syntax Correction
mysqldump -u root -pmytestdb > mytestdb.sql
Import:
mysql -u root -pmytestdb2 < mytestdb.sql
Syntax OK
mysqldump -u root -prootpw mytestdb > mytestdb.sql
...etc
Add new comment