This command is biased towards those developers who use MySQL. Iâ€™m positive there are identical commands for other RDBMS. Say you needed to move an entire site with itâ€™s database from one server to another. Youâ€™ve tarred up all the files, and youâ€™ve moved them to the new server via scp, but how do you get the database? Itâ€™s simple:
mysqldump -uroot -p databasename > dumpfile.sql
You will then be prompted for a password and, depending how large the database is, it may take a few seconds to return you to the command prompt. Substitute the â€˜rootâ€™ parameter for whatever username has access to the database you are trying to dump. The â€˜>â€™ redirects standard output to standard input and places the dumped data in the file â€˜dumpfile.sqlâ€™. You can then scp that file to your new server and use the â€˜mysqlâ€™ command to import the dumpfile.sql contents into whatever new database you want:
mysql -uroot -p newdatabase < dumpfile.sql
The database â€˜newdatabaseâ€™ must already exist. Notice the reverse â€˜< ' redirection operator which will send the contents of the dumpfile.sql file into the database specified.