Read MoreThe best VPS hosting starts from $5 per month!

How To Install Ghost on MySQL Database

If you have installed ghost using my Ghost Installation tutorial then The ghost installed on SQLite3 database, Even Ghost uses SQLite3 Database as default database for installation. But, If you would like to have your ghost blog on MySQL database, Then you will have to modify config.js file to make ghost run on MySQL.

Through This Tutorial, I will show you how to configure ghost to run on MySQL. But before you proceed, You need to have MySQL installed and configured. However this post covers How to Configure ghost on MySQL, that’s why We have skipped the MySQL installation and I assume that You have MySQL installed and If not, I recommend you to take a look to below the tutorial to learn how to Install and configure MySQL on our server.

Installing MySQL

For this tutorial, I’m going to use DigitalOcean’s Cloud Hosting and Ubuntu 14.04, Even most of the tutorials on this website based on DigitalOcean.

Okay! The first step is login your server using via SSH and then run the following commands:

sudo apt-get install mysql-server

By running the command above, Ubuntu will start installing MySQL on your server and during the installation, MySQL will ask you to set a password for the MySQL administrative user.

Configure mysql server

I recommend you to set a password.

Once MySQL installation is complete, MySQL service will be start automatically and then Login into MySQL server:

mysql -u root -p

Now, It will ask you to insert the password for root user that you have configured while installation.

And then, Create a new database:

create database DB_NAME;

(Make sure to update DB_NAME with the database name you want to create)

And a user:

CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';

(Replace user_name with the user you want to create and password with the user password.)

You are almost done, Now all you have to do is, Grant user to access the database and then Flush the newly granted privileges.

grant create,delete,insert,select,update,alter ON DB_NAME.* TO 'user_name'@'localhost';
flush privileges;

Update the DB_NAME & user_name with Database name and User name.

WooHooo!, You have completed the installation of MySQL and now all you have to do is, Configuring Ghost to use the MySQL database.

Configuring Ghost To Run On MySQL

In order to get ghost work on MySQL database, You will have to edit config.jsfile from Ghost installation directory. If you have followed our Ghost Installation on DigitalOcean then the installation directory should be /var/www/ghost.

Bu, before you start any modification on your Ghost blog’s config.js file, I recommend you to take a backup of your ghost blog by visiting www.yourblogurl.com/ghost/debug.

Edit config.js with your favorite editor or use standard editor:

sudo nano var/www/ghost/config.js

After that replace current database info with MySQL information.

Current Database Info is similar to:

database: {
        client: 'sqlite3',
        connection: {
            filename: path.join(__dirname, '/content/data/ghost2.db')
        },

Replace that with MySQL DB Information:

database: {
   client: 'mysql',
   connection: {
      host: 'localhost',
      user: 'user_name',
      password: 'User_Password',
      database: 'DB_NAME',
      charset: 'utf8'
  }

Important: Make Sure to update user_name, User-Password and DB_NAME with the correct information.

Tags:

Leave a Reply