fortypoundhead.com

Backup and Restore MySQL DBs via SSH

Posted On 2011-04-02 by FortyPoundHead
Keywords: Backup Restore SSH MySQL
Tags: Linux Commandline Tip Webmaster Related Linux
Views: 1113


Lets say your web host does not provide backups for your MySQL database(s). Or perhaps you are changing hosts, and you need retrieve the database. Follow these steps to grab a backup, easily.

Here’s how to export mysql DB to SQL file using at the command line, after telnetting in via SSH. Of course, I had to do it command line style!
mysqldump –user=username –password=1234 –databases your_database –opt –quote-names –complete-insert > example.sql
or you can use this command :
$ mysql -u username -p dbname > database.sql
If the MySQL programs are not in your path, you will need to manually specify the location of the mysqldump program:
$ /usr/local/mysql/bin/mysqldump -u username -p --opt dbname > database.sql
Download the database.sql and keep it in a safe place (CDR, Zip disk, etc).

If you need to restore your database, you can do so like this:
$ mysql -u username -p databasename < database.sql


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:23.20.157.174

Before you can post, you need to prove you are human. If you log in, this test goes away.


Beat With A Stick List Returns: By request, BWASL has returned to the site. Free your rage by telling the world about something that really grinds your gears. Add your beating.



Recent Forum Posts

BWASL returns
dwirch posted on May 13, 2017 at about 15:24 in Site News

BWASL returns
dwirch posted on May 13, 2017 at about 8:46 in Site News

Job Spammer: Balashankar Bose Bose
dwirch posted on May 11, 2017 at about 10:05 in Spammers

Job Spammer: Bharti Jigyasi
dwirch posted on May 11, 2017 at about 7:58 in Spammers

List of Shady Characters
dwirch posted on April 25, 2017 at about 16:39 in Webmaster Stuff

Job Spammer: Bilal Uddin
dwirch posted on April 25, 2017 at about 11:00 in Spammers