I run into these scenarios at least twice a week:
1. I made a clone of my server to test the functionality of a new module/post/theme, but ALL the links are broken
2. I renamed my website and have a new domain pointed to my server, I changed my domain name in wp-admin but there’s still broken content on my site.
3. I copied my website to another folder, exported, than imported to a new database, made a new Apache/Nginix config, and my site is broken when I load anything.
If you’re doing theme or plugin development, you will eventually need to jump into MySQL to fully integrate your application.
The default database structure consists of the following:
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_terms
wp_term_relationships
wp_term_taxonomy
wp_usermeta
wp_users
As you can imagine, the data from a mysqldump of a wordpress database basically contains THE ENTIRE WEBSITE.
With that being said, you can also assume there’s gonna be more than 2 or 3 fields containing the site url.. (images, content, etc.)
I’ve listed a few examples below:
*Example 1 [ superc00lsite.com - > superunc00lsite.com ]
1. mysqldump wpdb | tee wpdb.sql > wpdb.sqlbak
2. sed -i 's@http:\/\/superc00lsite.com@http:\/\/superunc00lsite.com@g' wpdb.sql
3. mysql -e "DROP DATABASE wpdb;"
4. mysql -e "CREATE DATABASE wpdb;"
5. mysql wpdb < wpdb.sql
6. test website
*Example 2 [ dev.mydogroofus.com - > mydogroofus.com + new directories + apache changes]
1. cp -r /var/www/vhosts/dev.mydogroofus.com /var/www/vhosts/mydogroofus.com
2. cp /etc/apache2/sites-enabled/dev.mydogroofus.com /etc/apache2/sites-enabled/mydogroofus.com
3. sed -i 's@dev.mydogroofus.com@mydogroofus.com@g' /etc/apache2/sites-enabled/mydogroofus.com
4. mysqldump roofus_devdb | tee r_devdb.sql > r_devdb.sqlbak
5. sed -i 's@http:\/\/dev.mydogroofus.com@http:\/\/mydogroofus.com@g' r_devdb.sql
6. mysql -e "DROP DATABASE roofus_devdb;"
7. mysql -e "CREATE DATABASE roofus_db;"
8. mysql roofus_db < r_devdb.sql
9. a2ensite mydogroofus.com
10. service apache2 reload
11. test site
Quick explanation of the sed command:
-i = edit the file in place
's@ = substitution begins, our delimiter inside of '' will be @
\/\/ = // you must escape your forward slashes, with a backslash
@ = delimiter mid point, separating the two data fields: old@new
@g' = substitution ends at the final delimiter
-crucif0rm