Export Wordpress database

Originally created for exporting database of a Wordpress site from development server to production server, however this can be use for any schema.

Exporting

$ mysqldump -Cnp schema_name|sed 's/local-domain/new-domain/g'|gzip >schema.sql.gz

 

Note: generated script does not create or specify the destination database to use. Intended to be imported in to an empty database.

Importing

$ echo "drop database if exists \`new_schema_name\`; create database \`new_schema_name\`; use \`new_schema_name\`; `zcat schema.sql.gz`"| \
> mysql -p

 

or

$ echo "drop database if exists \`new_schema_name\`; create database \`new_schema_name\`; use \`new_schema_name\`; `gzip -dc schema.sql.gz`"| \
> mysql -p