G Ghost

How to switch to MySQL database on Ghost

intermediate 12 min read Updated 2026-03-18
Quick Answer

Switching to MySQL on Ghost requires updating the database configuration in your config.production.json file and migrating your existing data. This process involves configuring MySQL connection settings and running Ghost's migration commands.

Prerequisites

  • MySQL server installed and running
  • Ghost installation with admin access
  • Basic knowledge of database configuration
  • Backup of existing Ghost data

Step-by-Step Instructions

1

Create MySQL database and user

Log into your MySQL server and create a new database for Ghost:
CREATE DATABASE ghost_production;
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON ghost_production.* TO 'ghostuser'@'localhost';
FLUSH PRIVILEGES;
Replace ghost_production with your preferred database name and set a strong password.
Use a strong password and note down the database credentials as you'll need them in the next step.
2

Stop Ghost service

Before making configuration changes, stop your Ghost instance to prevent data corruption:
ghost stop
If you're using a different process manager, use the appropriate command like sudo systemctl stop ghost_yourblog.
Always stop Ghost before modifying database configurations to avoid potential data loss.
3

Backup existing Ghost data

Export your current Ghost data through the admin panel or create a backup:
  • Navigate to SettingsLabsExport
  • Download the JSON file containing all your content
  • Alternatively, backup your current database files if using SQLite
Store this backup in a safe location before proceeding.
Always create multiple backups before major configuration changes - consider both JSON exports and file-level backups.
4

Update Ghost configuration file

Edit your Ghost configuration file (usually config.production.json) and update the database section:
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"port": 3306,
"user": "ghostuser",
"password": "your_secure_password",
"database": "ghost_production"
}
}
Replace the credentials with those created in step 1.
Keep a backup copy of your original configuration file before making changes.
5

Install MySQL dependencies

Install the required MySQL package for Ghost:
npm install mysql2 --save
Run this command from your Ghost installation directory. If you're using Ghost-CLI, it should handle dependencies automatically when you restart.
6

Run database migration

Initialize the MySQL database with Ghost's schema:
ghost setup migrate
This command will create all necessary tables and structures in your MySQL database. If using manual installation, run:
knex-migrator migrate --init
The migration process may take several minutes depending on your system performance.
7

Import existing data

Import your previously exported data through the Ghost admin panel:
  • Start Ghost with ghost start
  • Access your admin panel at /ghost
  • Go to SettingsLabsImport
  • Upload your JSON backup file
  • Review and confirm the import
Check that all content, users, and settings have been imported correctly before going live.
8

Verify the database switch

Confirm that Ghost is successfully using MySQL:
  • Check Ghost logs for any database connection errors
  • Verify your content appears correctly on the frontend
  • Test admin functionality like creating/editing posts
  • Monitor MySQL connections: SHOW PROCESSLIST; in MySQL
Monitor your site closely for the first 24 hours after switching to catch any potential issues early.

Common Issues & Troubleshooting

Connection refused error when starting Ghost

Verify MySQL service is running with sudo systemctl status mysql and check that connection credentials in config.production.json match your MySQL user setup.

Migration fails with permission errors

Ensure the MySQL user has full privileges on the database with GRANT ALL PRIVILEGES ON ghost_production.* TO 'ghostuser'@'localhost'; and run FLUSH PRIVILEGES;.

Ghost starts but admin panel shows blank content

The data import may have failed. Check Ghost logs for import errors and try re-importing your JSON backup file through SettingsLabsImport.

Performance issues after switching to MySQL

Optimize MySQL configuration by adjusting innodb_buffer_pool_size and query_cache_size in your MySQL configuration file, then restart MySQL service.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official Ghost website before purchasing.