Export and Import MySQL via the command line

If you use MySQL on a remote server for web sites, you may want a nice way of backing them up or moving them to another server (perhaps keeping 2 servers in sync). To get you started try this:

Use an SSH client, like putty (if your database is on a remote server), to connect to your server and export the databse you want simply with:

mysqldump --user=username --password=1234 --databases your_database --opt --quote-names --allow-keywords --complete-insert | bzip2 -c > your_database.sql.bz2

download the .bz2 file created, unzip it using 7-zip (if you dont have any other uncompress utility), and backup your database in mysql using:

mysql --user=username --password your_database < your_database.sql

Via Sephiroth.it

Also note, that if you have mysql installed locally, by including a host / port in the mysqldump arguements, you don't need to run the command remotely (although you would probably want to get mysql to do the compression rather than piping it through the bzip command).

I'll upload a full mysql mirror script in a few days. SteamSHIFT out.

Technorati Tags:
mysql, database, ssh

Copyright © 2013 - Brothers Bennettw - Powered by Hexo
- Ported theme GreyShade -