Change Ghost database from default MySQL to SQLite
1 min read

Change Ghost database from default MySQL to SQLite

Change Ghost database from default MySQL to SQLite

Ghost is really good software to publishing content. In fact it comes with predefined install steps where default and preferred database is MySQL. Ghost use  Bookshelf.js as a ORM layer and currently Ghost core team officially support only two engines: MySQL and SQLite. Notice this is official support so, in theory, blogging platform can use any other database engine. Unfortunately I didn't find any.

In this article I show you how to switch from recommended MySQL to SQLite. Sometimes this switch may be desirable (eg. to save resources or MySQL is not available).

Backup all data

First of all backup all of you content using Export your content from Migration Option (Labs section). This option export all your data to json file.

Switch database in configuration

When backup is ready you can switch database in configuration file config.production.json :

{
  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/var/www/example/app.db"
    }
  }
  // ...
}

Change path to your needs. If directory which contain database file is writable for ghost user you don't need to create file manually. Ghost take care of it. Otherwise you must create database file and set read + write privileges.

Setup Ghost and restore backup

When database is changed you can visit Ghost setup page at http://example.com/ghost once again and install fresh website. During installation there's no more question about database user and password.

After all restore your backup using similar Import content from Migration Option (Labs section).

Backup restore keep all currently available data like drafts, tags etc. You should check duplicates (if any) and remove them manually.

Conclusion

Switch from default MySQL database to SQLite is really simple and safe but this is also our only possibility. After all you may want to remove MySQL database to save resources.