Migrate your Ghost SQLite Database to MySQL

Migrate your Ghost SQLite Database to MySQL

Recently I saw some users on Twitter who were upset that the Docker community maintainers for the Ghost Docker image changed the default database from sqlite3 to MySQL. Since this was only a minor version update many of the sites powered by Ghost went down as soon as they updated their Docker image.

Since this blog here was also affected by this change I will now describe a way how you can migrate your containerized Ghost installation from sqlite3 to MySQL.

Note: You can follow along if you installed Ghost via docker-compose on a standalone host.

Export the Ghost content file

Your Ghost Admin Panel -> Settings -> Labs -> Export you content as .json file

Stop your ghost container

docker-compose down

Backup your data and remove any existing local database volume

Generally, it is a good idea to create a backup before any migration. For our task it could be something as simple as

cp -R /your/ghost/data /tmp/ghost_migration

Modify your docker-compose.yml file

version: "3"

services:
    ghost:
        image: ghost:5.10.1
        container_name: ghost
        restart: unless-stopped
        volumes:
          - "/data/ghost:/var/lib/ghost/content"
        environment:
          database__client: mysql
          database__connection__host: db
          database__connection__user: root
          database__connection__password: $ghost_mysql_password
          database__connection__database: ghost
        depends_on:
            - db

    db:
      image: mysql:8.0
      restart: unless-stopped
      container_name: ghost-mysql-db
      environment:
        MYSQL_ROOT_PASSWORD: $ghost_mysql_password
      networks:
          - internal
      volumes:
          - ghost_db:/var/lib/mysql

volumes:
  ghost_db:

In my case, I've added a new service called 'db' in this file and linked it with my ghost container. The following snippet is the bare minimum of what you need for your container to start successfully. I assume you already have a way to handle your traffic for the ghost container. If not I can recommend traefik as a proxy.

Remember to change the password for the database connection between those two containers.

Reconfigure your Ghost site

Go to your website and navigate to your admin panel (/ghost) and create the same user/password that you already had on your old setup.


Go to Settings -> Lab -> Import content -> Upload the JSON file that you downloaded on step 1 -> Import


After the migration, I would recommend creating a backup mechanism for the content folder and backup the .json file regularly.