Replicating a mySQL database

The database

If you’re running a site that uses mySQL then you’ll need to export the data into a text file (.sql) somewhere on the file system.

If you don’t have root or sudo access then choose somewhere in your home folder:

cd ~/

Then run the following command replacing user_name with your mySQL username,database_name with the name of the database you want to export and filename

with a descriptive name for your export file:

mysqldump -p -u user_name database_name > filename.sql

To import the files contents into your new database run the following command replacing the same details as previous:

mysql -p -u user_name database_name < filename.sql

You should now have an exact replica of your database ready for use.

Leave a Reply