How to Dump and Import a Database or Table using the CLI on Linux

Posted by: scoopseven 15 years, 10 months ago

Log onto your server from the console or with a ssh client. I use Putty. Use the following command to dump a table.
myserver# mysqldump -u yourUserName -p yourDatabaseName yourTableName > yourDestinationFileName.sql
Use this command to dump a whole database (this may take a while). I'm using putting the dump file into a directory below too. Just to add to the example.
myserver# mysqldump -u yourUserName -p yourDatabaseName > /yourDestinationDirectory/yourDestinationFileName.sql
Because I'm moving this to another Linux DB server, I'm going to use scp to copy the file over
myserver# scp theFileIDumpedAbove.sql yourUserName@yourDestinationServer:/yourDestinationDir/yourDestinationFile.sql
Finally, on my destination server, where I just scp'ed the file to, I import my dump file into my database. If you're replacing tables, make sure you drop those tables from the DB before you try to import them.
myserver# mysql -p yourDestinationDatabase < /yourSourceDirectory/yourSourceSqlFile.sql

Currently unrated


Recent Tweets

Recent Posts

Archive

2013
2012
2011
2010
2009
2008
2007
2006

Categories

Authors

Feeds

RSS / Atom