Migrate to ghost 2 from WordPress

Jim Kang
Jim Kang
Aug 8 · 2 min read

This guide will import ONLY posts and feature image. Current migration only supports ghost v1, so if you don’t care about users and other stuff, read on!

Main Steps

  1. Export wp_posts and wp_postmeta from word-press
  2. Have ghost db created and restore above 2 table over
  3. Run a(my) node script

Step 1: Export those tables

the only two tables that we need are wp_posts and wp_postmeta tables.
postmeta will contain feature image information that we need to each post. Feel free to use any backup tools or PHPMyAdmin for exporting these two tables from your WordPress site

Step 2: Import those tables

After running ghost install you should find ghost’s DB created in your DB (I’m using MySQL). We’re going to import those two tables into our ghost’s DB and later remove them when we’re done with the migration.

Importing are done through

mysql -h YOUR_HOST -u USER_NAME -p GHOST_DB_NAME < BACKUP_TABLE.sql

BACKUP_TABLE are those two tables: wp_posts and wp_postmeta

Step 3: Run nodejs script

Head to your ghost’s backend and create an integration, note down the Admin API Key

Head over to this repo

After you clone or download, just run npm install or yarn (your choice). When you’re done grabbing the package, open modify the correct info in main.js

After you’ve updated the correct config, execute

node main.js

Troubleshoot

If you’ve found that your blog has some weird symbol, it might be the incorrect encoding set in ghost’s DB.

  1. stop ghost with ghost stop
  2. delete (drop) ghost table, let’s say the DB name is ghost
  3. create table ghost with MySQL command create database ghost (assuming the name of ghost’s DB name is ghost)
  4. run ghost start

By default ghost use
utf8mb4 for DEFAULT_CHARACTER_SET_NAME
utf8mb4_general_ci for DEFAULT_COLLATION_NAME

But I found that using
latin1 for DEFAULT_CHARACTER_SET_NAME
latin1_swedish_ci for DEFAULT_COLLATION_NAME

works without encoding problem.

Happy Migration!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade