How to switch to MySQL database on Ghost
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
Create MySQL database and user
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.Stop Ghost service
ghost stopIf you're using a different process manager, use the appropriate command like sudo systemctl stop ghost_yourblog.Backup existing Ghost data
- Navigate to Settings → Labs → Export
- Download the JSON file containing all your content
- Alternatively, backup your current database files if using SQLite
Update Ghost configuration file
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.Install MySQL dependencies
npm install mysql2 --saveRun this command from your Ghost installation directory. If you're using Ghost-CLI, it should handle dependencies automatically when you restart.Run database migration
ghost setup migrateThis command will create all necessary tables and structures in your MySQL database. If using manual installation, run:knex-migrator migrate --initImport existing data
- Start Ghost with
ghost start - Access your admin panel at
/ghost - Go to Settings → Labs → Import
- Upload your JSON backup file
- Review and confirm the import
Verify the database switch
- 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
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 Settings → Labs → Import.
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.