BLog

ImprintImpressum
PrivacyDatenschutz
DisclaimerHaftung
Downloads 

Transfer of the MySQL data of a WordPress Site to a different domain

The internal links of a WordPress site are stored by their full URL into the database, and therefore a straight copy of a WordPress database would work only if the other WordPress site got exactly the same URL.

The solution is to run a mysqldump(1) on the master site and then transfer the generated .sql-file to the other machine:

mysqldump --user=root --password=uLtRaSeCrEt12345 --default-character-set=utf8 --set-gtid-purged=OFF wpdbname > wpdump.sql

Since the MySQL dump is simply a text file of MySQL commands and the contents are in plain text, I may utilize sed(1) for substituting in the SQL dump the URL of the master site - in my case https://blog.obsigna.net - by the URL of my local development site https://local.obsigna.net. I wrote a shell script for doing this which executes the mysqldump on the remote machine via ssh(1):

#!/bin/sh
ssh root@server.obsigna.net mysqldump --user=root --password=uLtRaSeCrEt12345 --default-character-set=utf8 --set-gtid-purged=OFF wpdbname 1> /tmp/wpdump.sql 2>/dev/null

sed -e 's|https://blog.obsigna.net|https://local.obsigna.net|g' -i "" /tmp/wpdump.sql
sed -e 's|%2Fblog.obsigna.net|%2Flocal.obsigna.net|g' -i "" /tmp/wpdump.sql
echo "drop database wpdbname; create database wpdbname;" | mysql --user=root --password=uLtRaSeCrEt12345 --host=localhost --default-character-set=utf8
mysql --user=root --password=uLtRaSeCrEt12345 --host=localhost --default-character-set=utf8 wpdbname < /tmp/wpdump.sql
rm -f /tmp/wpdump.sql
  • Of course I would need to adapt the script for different URL’s respectively.
  • Of course I would need to set up a working MySQL/WordPress installation on a new machine.
  • Of course I would need to transfer image and media data as well by using for example scp(1).

Keywords: MySQL-Script, WordPress

Copyright © Dr. Rolf Jansen - 2018-02-27 21:00:08

PROMOTION